From 402e6421b37314a278e8dead2c96a69cc9cd1f1f Mon Sep 17 00:00:00 2001 From: Dino Date: Tue, 14 Oct 2025 21:29:48 -0400 Subject: [PATCH] #607 - fix gtk3.22 & gtk4 client problems with & char in strings --- client/gui-gtk-3.22/citydlg.c | 12 +++++++----- client/gui-gtk-3.22/cityrep.c | 8 ++++++-- client/gui-gtk-3.22/diplodlg.c | 15 +++++++++++---- client/gui-gtk-3.22/plrdlg.c | 5 +++-- client/gui-gtk-3.22/repodlgs.c | 8 ++++++-- client/gui-gtk-4.0/citydlg.c | 12 +++++++----- client/gui-gtk-4.0/diplodlg.c | 15 +++++++++++---- client/gui-gtk-4.0/plrdlg.c | 5 +++-- client/gui-gtk-4.0/repodlgs.c | 8 ++++++-- 9 files changed, 60 insertions(+), 28 deletions(-) diff --git a/client/gui-gtk-3.22/citydlg.c b/client/gui-gtk-3.22/citydlg.c index 0150392b51..f1245ee005 100644 --- a/client/gui-gtk-3.22/citydlg.c +++ b/client/gui-gtk-3.22/citydlg.c @@ -1831,32 +1831,34 @@ static void city_dialog_update_title(struct city_dialog *pdialog) { gchar *buf; const gchar *now; + const char * city_name = city_name_get(pdialog->pcity); + gchar *escaped_city_name = g_markup_escape_text(city_name, -1);; if (city_unhappy(pdialog->pcity)) { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens - DISORDER"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } else if (city_celebrating(pdialog->pcity)) { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens - celebrating"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } else if (city_happy(pdialog->pcity)) { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens - happy"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } else { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } now = gtk_label_get_text(GTK_LABEL(pdialog->name_label)); if (strcmp(now, buf) != 0) { - gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name_get(pdialog->pcity)); + gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name); gtk_label_set_markup(GTK_LABEL(pdialog->name_label), buf); } diff --git a/client/gui-gtk-3.22/cityrep.c b/client/gui-gtk-3.22/cityrep.c index b7e8e78807..09938a2ab9 100644 --- a/client/gui-gtk-3.22/cityrep.c +++ b/client/gui-gtk-3.22/cityrep.c @@ -334,6 +334,8 @@ static void append_impr_or_unit_to_menu_item(GtkMenuItem *parent_item, int i, item, targets_used; char *row[4]; char buf[4][64]; + char *item_text; + gchar *escaped_item_text; GtkSizeGroup *group[3]; const char *markup[3] = { @@ -406,15 +408,17 @@ static void append_impr_or_unit_to_menu_item(GtkMenuItem *parent_item, for (i = 0; i < 3; i++) { if (row[i][0] == '\0') { - continue; + continue; } if (city_operation == CO_SELL && i != 0) { continue; } + item_text = row[i]; + escaped_item_text = g_markup_escape_text(item_text, -1); fc_snprintf(txt, ARRAY_SIZE(txt), "%s", - markup[i], row[i]); + markup[i], escaped_item_text); label = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(label), txt); diff --git a/client/gui-gtk-3.22/diplodlg.c b/client/gui-gtk-3.22/diplodlg.c index b884663fbf..81adba7233 100644 --- a/client/gui-gtk-3.22/diplodlg.c +++ b/client/gui-gtk-3.22/diplodlg.c @@ -698,6 +698,7 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, GtkListStore *store; GtkCellRenderer *rend; int i; + gchar *escaped; struct Diplomacy_dialog *pdialog; char plr_buf[4 * MAX_LEN_NAME]; @@ -765,8 +766,9 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, label = gtk_label_new(NULL); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text(nation_plural_for_player(plr0), -1); buf = g_strdup_printf("%s", - nation_plural_for_player(plr0)); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_container_add(GTK_CONTAINER(vbox), label); @@ -786,8 +788,10 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, gtk_widget_set_hexpand(label, TRUE); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text( + ruler_title_for_player(plr0, plr_buf, sizeof(plr_buf)), -1); buf = g_strdup_printf("%s", - ruler_title_for_player(plr0, plr_buf, sizeof(plr_buf))); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_container_add(GTK_CONTAINER(hbox), label); @@ -847,8 +851,9 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, label = gtk_label_new(NULL); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text(nation_plural_for_player(plr1), -1); buf = g_strdup_printf("%s", - nation_plural_for_player(plr1)); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_container_add(GTK_CONTAINER(vbox), label); @@ -868,8 +873,10 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, gtk_widget_set_hexpand(label, TRUE); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text( + title_for_player(plr1, plr_buf, sizeof(plr_buf)), -1); buf = g_strdup_printf("%s", - title_for_player(plr1, plr_buf, sizeof(plr_buf))); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_container_add(GTK_CONTAINER(hbox), label); diff --git a/client/gui-gtk-3.22/plrdlg.c b/client/gui-gtk-3.22/plrdlg.c index 136fab55ac..1fcea00a4c 100644 --- a/client/gui-gtk-3.22/plrdlg.c +++ b/client/gui-gtk-3.22/plrdlg.c @@ -652,6 +652,8 @@ static void fill_row(GtkListStore *store, GtkTreeIter *it, GdkPixbuf *pixbuf; int style = PANGO_STYLE_NORMAL, weight = PANGO_WEIGHT_NORMAL; int k; + const char * score_tt = score_tooltip(pplayer, pplayer->score.game); + gchar *escaped_score_tt = g_markup_escape_text(score_tt, -1); for (k = 0; k < num_player_dlg_columns; k++) { pcol = &player_dlg_columns[k]; @@ -680,8 +682,7 @@ static void fill_row(GtkListStore *store, GtkTreeIter *it, } } - gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP, - score_tooltip(pplayer, pplayer->score.game), -1); + gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP, escaped_score_tt, -1); /* Now add some eye candy ... */ if (client_has_player()) { diff --git a/client/gui-gtk-3.22/repodlgs.c b/client/gui-gtk-3.22/repodlgs.c index 8d200b68a0..60eeba4b25 100644 --- a/client/gui-gtk-3.22/repodlgs.c +++ b/client/gui-gtk-3.22/repodlgs.c @@ -1921,13 +1921,17 @@ void endgame_report_dialog_player(const struct packet_endgame_player *packet) const struct player *pplayer = player_by_number(packet->player_id); GtkTreeIter iter; int i; + const char * player_nm = player_name(pplayer); + gchar *escaped_player_nm = g_markup_escape_text(player_nm, -1); + const char * score_tt = score_tooltip(pplayer, pplayer->score.game); + gchar *escaped_score_tt = g_markup_escape_text(score_tt, -1); gtk_list_store_append(preport->store, &iter); gtk_list_store_set(preport->store, &iter, - FRD_COL_PLAYER, player_name(pplayer), + FRD_COL_PLAYER, escaped_player_nm, FRD_COL_NATION, get_flag(nation_of_player(pplayer)), FRD_COL_SCORE, packet->score, - FRD_COL_TOOLTIP, score_tooltip(pplayer, packet->score), + FRD_COL_TOOLTIP, escaped_score_tt, -1); for (i = 0; i < packet->category_num; i++) { gtk_list_store_set(preport->store, &iter, diff --git a/client/gui-gtk-4.0/citydlg.c b/client/gui-gtk-4.0/citydlg.c index 6a84af7a3c..3b0ab10acb 100644 --- a/client/gui-gtk-4.0/citydlg.c +++ b/client/gui-gtk-4.0/citydlg.c @@ -1815,32 +1815,34 @@ static void city_dialog_update_title(struct city_dialog *pdialog) { gchar *buf; const gchar *now; + const char * city_name = city_name_get(pdialog->pcity); + gchar *escaped_city_name = g_markup_escape_text(city_name, -1);; if (city_unhappy(pdialog->pcity)) { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens - DISORDER"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } else if (city_celebrating(pdialog->pcity)) { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens - celebrating"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } else if (city_happy(pdialog->pcity)) { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens - happy"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } else { /* TRANS: city dialog title */ buf = g_strdup_printf(_("%s - %s citizens"), - city_name_get(pdialog->pcity), + escaped_city_name, population_to_text(city_population(pdialog->pcity))); } now = gtk_label_get_text(GTK_LABEL(pdialog->name_label)); if (strcmp(now, buf) != 0) { - gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name_get(pdialog->pcity)); + gtk_window_set_title(GTK_WINDOW(pdialog->shell), city_name); gtk_label_set_markup(GTK_LABEL(pdialog->name_label), buf); } diff --git a/client/gui-gtk-4.0/diplodlg.c b/client/gui-gtk-4.0/diplodlg.c index 080f06aba7..d0c87196c5 100644 --- a/client/gui-gtk-4.0/diplodlg.c +++ b/client/gui-gtk-4.0/diplodlg.c @@ -775,6 +775,7 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, int main_row = 0; GActionGroup *group; GMenu *menu; + gchar *escaped; pdialog = fc_malloc(sizeof(*pdialog)); @@ -834,8 +835,9 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, label = gtk_label_new(NULL); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text(nation_plural_for_player(plr0), -1); buf = g_strdup_printf("%s", - nation_plural_for_player(plr0)); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_box_append(GTK_BOX(vbox), label); @@ -856,8 +858,10 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, gtk_widget_set_hexpand(label, TRUE); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text( + ruler_title_for_player(plr0, plr_buf, sizeof(plr_buf)), -1); buf = g_strdup_printf("%s", - ruler_title_for_player(plr0, plr_buf, sizeof(plr_buf))); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_grid_attach(GTK_GRID(hgrid), label, grid_col++, 0, 1, 1); @@ -912,8 +916,9 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, label = gtk_label_new(NULL); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text(nation_plural_for_player(plr1), -1); buf = g_strdup_printf("%s", - nation_plural_for_player(plr1)); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_box_append(GTK_BOX(vbox), label); @@ -935,8 +940,10 @@ static struct Diplomacy_dialog *create_diplomacy_dialog(struct Treaty *ptreaty, gtk_widget_set_hexpand(label, TRUE); gtk_widget_set_halign(label, GTK_ALIGN_CENTER); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); + escaped = g_markup_escape_text( + title_for_player(plr1, plr_buf, sizeof(plr_buf)), -1); buf = g_strdup_printf("%s", - title_for_player(plr1, plr_buf, sizeof(plr_buf))); + escaped); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); gtk_grid_attach(GTK_GRID(hgrid), label, grid_col++, 0, 1, 1); diff --git a/client/gui-gtk-4.0/plrdlg.c b/client/gui-gtk-4.0/plrdlg.c index fb1650a60a..263d8f42d2 100644 --- a/client/gui-gtk-4.0/plrdlg.c +++ b/client/gui-gtk-4.0/plrdlg.c @@ -787,6 +787,8 @@ static void fill_row(GtkListStore *store, GtkTreeIter *it, GdkPixbuf *pixbuf; int style = PANGO_STYLE_NORMAL, weight = PANGO_WEIGHT_NORMAL; int k; + const char * score_tt = score_tooltip(pplayer, pplayer->score.game); + gchar *escaped_score_tt = g_markup_escape_text(score_tt, -1); for (k = 0; k < num_player_dlg_columns; k++) { pcol = &player_dlg_columns[k]; @@ -815,8 +817,7 @@ static void fill_row(GtkListStore *store, GtkTreeIter *it, } } - gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP, - score_tooltip(pplayer, pplayer->score.game), -1); + gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP, escaped_score_tt, -1); /* Now add some eye candy ... */ if (client_has_player()) { diff --git a/client/gui-gtk-4.0/repodlgs.c b/client/gui-gtk-4.0/repodlgs.c index 43837ade09..aa95685047 100644 --- a/client/gui-gtk-4.0/repodlgs.c +++ b/client/gui-gtk-4.0/repodlgs.c @@ -1947,13 +1947,17 @@ void endgame_report_dialog_player(const struct packet_endgame_player *packet) const struct player *pplayer = player_by_number(packet->player_id); GtkTreeIter iter; int i; + const char * player_nm = player_name(pplayer); + gchar *escaped_player_nm = g_markup_escape_text(player_nm, -1); + const char * score_tt = score_tooltip(pplayer, pplayer->score.game); + gchar *escaped_score_tt = g_markup_escape_text(score_tt, -1); gtk_list_store_append(preport->store, &iter); gtk_list_store_set(preport->store, &iter, - FRD_COL_PLAYER, player_name(pplayer), + FRD_COL_PLAYER, escaped_player_nm, FRD_COL_NATION, get_flag(nation_of_player(pplayer)), FRD_COL_SCORE, packet->score, - FRD_COL_TOOLTIP, score_tooltip(pplayer, packet->score), + FRD_COL_TOOLTIP, escaped_score_tt, -1); for (i = 0; i < packet->category_num; i++) { gtk_list_store_set(preport->store, &iter, -- 2.31.0