Commit 0731de03 authored by Stepan Salenikovich's avatar Stepan Salenikovich Committed by Nicolas Jager

escape pango markup formatted strings

To make sure string contents don't get interpreted as markup.

Change-Id: I0463014b43bd327865983d86b48d966c34cb7cbd
Tuleap: #705
parent 1cf27113
......@@ -334,29 +334,31 @@ state_to_string(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
auto account = AccountModel::instance().getAccountByModelIndex(idx);
auto humanState = account->toHumanStateName();
auto escaped_state = g_markup_escape_text(humanState.toUtf8().constData(), -1);
/* we want the color of the status text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected) {
display_state = g_strdup_printf("%s", humanState.toUtf8().constData());
display_state = escaped_state;
} else {
switch (account->registrationState()) {
case Account::RegistrationState::READY:
display_state = g_strdup_printf("<span fgcolor=\"green\">%s</span>", humanState.toUtf8().constData());
display_state = g_strdup_printf("<span fgcolor=\"green\">%s</span>", escaped_state);
break;
case Account::RegistrationState::UNREGISTERED:
display_state = g_strdup_printf("<span fgcolor=\"gray\">%s</span>", humanState.toUtf8().constData());
display_state = g_strdup_printf("<span fgcolor=\"gray\">%s</span>", escaped_state);
break;
case Account::RegistrationState::TRYING:
display_state = g_strdup_printf("<span fgcolor=\"orange\">%s</span>", humanState.toUtf8().constData());
display_state = g_strdup_printf("<span fgcolor=\"orange\">%s</span>", escaped_state);
break;
case Account::RegistrationState::ERROR:
display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", escaped_state);
break;
case Account::RegistrationState::COUNT__:
g_warning("registration state should never be \"count\"");
display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", humanState.toUtf8().constData());
display_state = g_strdup_printf("<span fgcolor=\"red\">%s</span>", escaped_state);
break;
}
g_free(escaped_state);
}
}
......
......@@ -119,7 +119,7 @@ render_name_and_contact_method(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
QVariant var = idx.data(Qt::DisplayRole);
if (depth == 1) {
/* category */
text = g_strdup_printf("<b>%s</b>", var.value<QString>().toUtf8().constData());
text = g_markup_printf_escaped("<b>%s</b>", var.value<QString>().toUtf8().constData());
} else if (depth == 2) {
/* contact, check for contact methods */
QVariant var_c = idx.data(static_cast<int>(Person::Role::Object));
......@@ -139,37 +139,37 @@ render_name_and_contact_method(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
/* we want the color of the status text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected) {
text = g_strdup_printf("%s\n %s",
c->formattedName().toUtf8().constData(),
number.toUtf8().constData());
text = g_markup_printf_escaped("%s\n %s",
c->formattedName().toUtf8().constData(),
number.toUtf8().constData());
} else {
text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
c->formattedName().toUtf8().constData(),
number.toUtf8().constData());
text = g_markup_printf_escaped("%s\n <span fgcolor=\"gray\">%s</span>",
c->formattedName().toUtf8().constData(),
number.toUtf8().constData());
}
break;
}
default:
/* more than one, for now don't show any of the contact methods */
text = g_strdup_printf("%s\n", c->formattedName().toUtf8().constData());
text = g_markup_printf_escaped("%s\n", c->formattedName().toUtf8().constData());
break;
}
} else {
/* should never happen since depth 2 should always be a contact (person) */
text = g_strdup_printf("%s", var.value<QString>().toUtf8().constData());
text = g_markup_printf_escaped("%s", var.value<QString>().toUtf8().constData());
}
} else {
auto var_object = idx.data(static_cast<int>(Ring::Role::Object));
auto cm = var_object.value<ContactMethod *>();
if (cm && cm->category()) {
// try to get the number category, eg: "home"
text = g_strdup_printf("(%s) %s", cm->category()->name().toUtf8().constData(),
cm->uri().toUtf8().constData());
text = g_markup_printf_escaped("(%s) %s", cm->category()->name().toUtf8().constData(),
cm->uri().toUtf8().constData());
} else if (cm) {
text = g_strdup_printf("%s", cm->uri().toUtf8().constData());
text = g_markup_printf_escaped("%s", cm->uri().toUtf8().constData());
} else {
/* should only ever be a CM, so this should never execute */
text = g_strdup_printf("%s", var.value<QString>().toUtf8().constData());
text = g_markup_printf_escaped("%s", var.value<QString>().toUtf8().constData());
}
}
}
......
......@@ -247,10 +247,9 @@ edit_contact_view_new(ContactMethod *cm, Person *p)
EditContactViewPrivate *priv = EDIT_CONTACT_VIEW_GET_PRIVATE(self);
priv->cm = cm;
gtk_label_set_markup(
GTK_LABEL(priv->label_uri),
(QString("<b>") + cm->uri() + QString("</b>")).toUtf8().constData()
);
auto uri_escaped = g_markup_printf_escaped("<b>%s</b>", cm->uri().toUtf8().constData());
gtk_label_set_markup(GTK_LABEL(priv->label_uri), uri_escaped);
g_free(uri_escaped);
/* use the primaryName as the suggested name (usually the display name), unless it is the same
* as the uri */
......
......@@ -302,7 +302,7 @@ render_name_and_contact_method(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
QVariant var = idx.data(Qt::DisplayRole);
if (depth == 1) {
/* category */
text = g_strdup_printf("<b>%s</b>", var.value<QString>().toUtf8().constData());
text = g_markup_printf_escaped("<b>%s</b>", var.value<QString>().toUtf8().constData());
} else if (depth == 2) {
/* call item */
QVariant var_name = idx.data(static_cast<int>(Call::Role::Name));
......@@ -311,13 +311,13 @@ render_name_and_contact_method(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
/* we want the color of the status text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected) {
text = g_strdup_printf("%s\n %s",
var_name.value<QString>().toUtf8().constData(),
var_number.value<QString>().toUtf8().constData());
text = g_markup_printf_escaped("%s\n %s",
var_name.value<QString>().toUtf8().constData(),
var_number.value<QString>().toUtf8().constData());
} else {
text = g_strdup_printf("%s\n <span fgcolor=\"gray\">%s</span>",
var_name.value<QString>().toUtf8().constData(),
var_number.value<QString>().toUtf8().constData());
text = g_markup_printf_escaped("%s\n <span fgcolor=\"gray\">%s</span>",
var_name.value<QString>().toUtf8().constData(),
var_number.value<QString>().toUtf8().constData());
}
}
}
......@@ -350,14 +350,14 @@ render_date_time(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
/* we want the color of the text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected) {
text = g_strdup_printf("%s\n%s",
date_time.time().toString().toUtf8().constData(),
date_time.date().toString().toUtf8().constData()
text = g_markup_printf_escaped("%s\n%s",
date_time.time().toString().toUtf8().constData(),
date_time.date().toString().toUtf8().constData()
);
} else {
text = g_strdup_printf("%s\n<span fgcolor=\"gray\">%s</span>",
date_time.time().toString().toUtf8().constData(),
date_time.date().toString().toUtf8().constData()
text = g_markup_printf_escaped("%s\n<span fgcolor=\"gray\">%s</span>",
date_time.time().toString().toUtf8().constData(),
date_time.date().toString().toUtf8().constData()
);
}
}
......
......@@ -198,13 +198,13 @@ render_name_and_info(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
/* we want the color of the status text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected) {
text = g_strdup_printf("%s\n<span size=\"smaller\">%s</span>",
name.toUtf8().constData(),
status.toUtf8().constData());
text = g_markup_printf_escaped("%s\n<span size=\"smaller\">%s</span>",
name.toUtf8().constData(),
status.toUtf8().constData());
} else {
text = g_strdup_printf("%s\n<span size=\"smaller\" color=\"gray\">%s</span>",
name.toUtf8().constData(),
status.toUtf8().constData());
text = g_markup_printf_escaped("%s\n<span size=\"smaller\" color=\"gray\">%s</span>",
name.toUtf8().constData(),
status.toUtf8().constData());
}
}
break;
......@@ -216,7 +216,7 @@ render_name_and_info(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
if (is_conference) {
auto var_name = idx.data(static_cast<int>(Ring::Role::Name));
text = g_markup_printf_escaped("%s", var_name.value<QString>().toUtf8().constData());
text = g_markup_escape_text(var_name.value<QString>().toUtf8().constData(), -1);
} else {
auto parent_source = RecentModel::instance().peopleProxy()->mapToSource(idx.parent());
if (RecentModel::instance().isConference(parent_source)) {
......@@ -225,10 +225,13 @@ render_name_and_info(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
/* we want the color of the name text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected)
text = g_strdup_printf("<span size=\"smaller\">%s</span>", var_name.value<QString>().toUtf8().constData());
else
text = g_strdup_printf("<span size=\"smaller\" color=\"gray\">%s</span>", var_name.value<QString>().toUtf8().constData());
if (is_selected) {
text = g_markup_printf_escaped("<span size=\"smaller\">%s</span>",
var_name.value<QString>().toUtf8().constData());
} else {
text = g_markup_printf_escaped("<span size=\"smaller\" color=\"gray\">%s</span>",
var_name.value<QString>().toUtf8().constData());
}
} else {
// just a call, so display the state
auto var_status = idx.data(static_cast<int>(Ring::Role::FormattedState));
......@@ -240,10 +243,13 @@ render_name_and_info(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
/* we want the color of the status text to be the default color if this iter is
* selected so that the treeview is able to invert it against the selection color */
if (is_selected)
text = g_strdup_printf("<span size=\"smaller\">%s</span>", status.toUtf8().constData());
else
text = g_strdup_printf("<span size=\"smaller\" color=\"gray\">%s</span>", status.toUtf8().constData());
if (is_selected) {
text = g_markup_printf_escaped("<span size=\"smaller\">%s</span>",
status.toUtf8().constData());
} else {
text = g_markup_printf_escaped("<span size=\"smaller\" color=\"gray\">%s</span>",
status.toUtf8().constData());
}
}
}
}
......@@ -284,7 +290,7 @@ render_call_duration(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
&& (idx_source.model()->rowCount(idx_source) == 1)
&& duration.isValid())
{
text = g_strdup_printf("%s", duration.value<QString>().toUtf8().constData());
text = g_markup_escape_text(duration.value<QString>().toUtf8().constData(), -1);
}
}
break;
......@@ -298,7 +304,7 @@ render_call_duration(G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
auto duration = idx.data(static_cast<int>(Ring::Role::Length));
if (duration.isValid())
text = g_strdup_printf("%s", duration.value<QString>().toUtf8().constData());
text = g_markup_escape_text(duration.value<QString>().toUtf8().constData(), -1);
}
}
break;
......
......@@ -696,18 +696,16 @@ autocompletion_name_render(G_GNUC_UNUSED GtkCellLayout *cell_layout,
GtkTreeIter *iter,
G_GNUC_UNUSED gpointer user_data)
{
gchar *text = nullptr;
QModelIndex idx = get_qidx_from_filter_model(GTK_TREE_MODEL_FILTER(model), iter);
if (idx.isValid()) {
QVariant name = idx.sibling(idx.row(), 1).data(Qt::DisplayRole);
gchar *text = g_strdup_printf("<span weight=\"bold\">%s</span>",
name.value<QString>().toUtf8().constData());
g_object_set(G_OBJECT(cell), "markup", text, NULL);
g_free(text);
return;
text = g_markup_printf_escaped("<span weight=\"bold\">%s</span>",
name.value<QString>().toUtf8().constData());
}
g_object_set(G_OBJECT(cell), "markup", NULL, NULL);
g_object_set(G_OBJECT(cell), "markup", text, NULL);
g_free(text);
}
static void
......@@ -717,17 +715,15 @@ autocompletion_number_render(G_GNUC_UNUSED GtkCellLayout *cell_layout,
GtkTreeIter *iter,
G_GNUC_UNUSED gpointer user_data)
{
gchar *text = nullptr;
QModelIndex idx = get_qidx_from_filter_model(GTK_TREE_MODEL_FILTER(model), iter);
if (idx.isValid()) {
QVariant uri = idx.data(Qt::DisplayRole);
gchar *text = g_strdup_printf("%s", uri.value<QString>().toUtf8().constData());
g_object_set(G_OBJECT(cell), "markup", text, NULL);
g_free(text);
return;
text = g_markup_escape_text(uri.value<QString>().toUtf8().constData(), -1);
}
g_object_set(G_OBJECT(cell), "markup", NULL, NULL);
g_object_set(G_OBJECT(cell), "markup", text, NULL);
g_free(text);
}
static void
......@@ -737,18 +733,16 @@ autocompletion_account_render(G_GNUC_UNUSED GtkCellLayout *cell_layout,
GtkTreeIter *iter,
G_GNUC_UNUSED gpointer user_data)
{
gchar *text = nullptr;
QModelIndex idx = get_qidx_from_filter_model(GTK_TREE_MODEL_FILTER(model), iter);
if (idx.isValid()) {
QVariant alias = idx.sibling(idx.row(), 2).data(Qt::DisplayRole);
gchar *text = g_strdup_printf("<span color=\"gray\">%s</span>",
alias.value<QString>().toUtf8().constData());
g_object_set(G_OBJECT(cell), "markup", text, NULL);
g_free(text);
return;
text = g_markup_printf_escaped("<span color=\"gray\">%s</span>",
alias.value<QString>().toUtf8().constData());
}
g_object_set(G_OBJECT(cell), "markup", NULL, NULL);
g_object_set(G_OBJECT(cell), "markup", text, NULL);
g_free(text);
}
static gboolean
......
......@@ -54,17 +54,19 @@ static void
show_ring_id(GtkLabel *label, Account *account) {
g_return_if_fail(label);
gchar *text = nullptr;
if (account) {
if (!account->username().isEmpty()) {
QString hash = "<span fgcolor=\"black\">" + account->username() + "</span>";
gtk_label_set_markup(label, hash.toUtf8().constData());
text = g_markup_printf_escaped("<span fgcolor=\"black\">%s</span>",
account->username().toUtf8().constData());
} else {
g_warning("got ring account, but Ring id is empty");
gtk_label_set_markup(label,
g_strdup_printf("<span fgcolor=\"gray\">%s</span>",
_("fetching RingID...")));
text = g_markup_printf_escaped("<span fgcolor=\"gray\">%s</span>",
_("fetching RingID..."));
}
}
gtk_label_set_markup(label, text);
g_free(text);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment