Project

General

Profile

Actions

Bug #607

open

Gtk-warning: unescaped ampersand

Added by Alina Lenk over 1 year ago. Updated 17 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
gtk3.22-client
Target version:
Start date:
05/13/2024
Due date:
% Done:

0%

Estimated time:

Description

Noticed when playing with Alien World ruleset:

(freeciv-gtk3.22:5387): Gtk-WARNING **: 22:19:20.657: Failed to set text 'J&W Corporation: score 155' from markup due to error parsing markup: Error on line 1: Entity did not end with a semicolon; most likely you used an ampersand character without intending to start an entity — escape ampersand as &

Probably affects other gtk clients as well.


Files

607.patch (15.7 KB) 607.patch Dean Brown, 10/15/2025 04:39 AM
Actions #1

Updated by Dean Brown 17 days ago

Some mission creep here, which I've tried to limit.
Ampersand in other text strings also cause display problems, found them with unit name, improvement name, leader name and city name.
There may possibly be more.

The reported bug is due to this code in .../client/gui-gtk-3/plrdlg.c routine fill_row()

gtk_list_store_set(store, it, PLR_DLG_COL_TOOLTIP,
score_tooltip(pplayer, pplayer->score.game), -1);

So some calls to gtk_list_store_set() and gtk_list_store_set_value() need to have g_markup_escape_text() called on text first.
In .../client/gui-gtk-3 there are 111 calls in 18 files (not all of them deal with text), and only 4 calls to g_markup_escape_text().
Not going to check them all.

Testing the leader name with & shows a call in .../client/gui-gtk-3/editgui.c routine refresh_player_pov_indicator() to
gtk_list_store_set() with unescaped player_name(pplayer) and the & works OK. The differences are
1 one is a tooltip, the other isn't
2 one has gtk_tree_view_column_new_with_attributes(), the other doesn't.
Pretty sure the attributes are the important thing. In .../client/gui-gtk-3 there are 47 such attribute calls in 18 files.
Not going to check them all.

Searching for score_tooltip() finds a call to gtk_list_store_set() in .../client/gui-gtk-3/repodlgs.c routine
endgame_report_dialog_player(), which is very similar to the one in .../client/gui-gtk-3/plrdlg.c routine
fill_row() and looks like it needs a similar fix.

A leader name with & causes problems in .../client/gui-gtk-3/diplodlg.c, routine create_diplomacy_dialog(),
where 4 calls to gtk_label_set_markup() need fixing.
So some calls to gtk_label_set_markup() also need g_markup_escape_text(). There's 7 more of them.

#1 in .../client/gui-gtk-3/citydlg.c routine city_dialog_update_title() is a problem when the city name has &, needs a fix.
#2 in .../client/gui-gtk-3/cityrep.c routine append_impr_or_unit_to_menu_item() is a problem when a unit name or improvement name has &,
needs a fix.
#3, #4, #5 are in the edit mode code and are not a problem.
#6 in .../client/gui-gtk-3/messagedlg.c routine create_messageopt_dialog() is not a problem.
#7 in .../client/gui-gtk-3/voteinfo_bar.c routine voteinfo_gui_update() already has calls to g_markup_escape_text(), is not a problem.

gtk4 client is same except for .../client/gui-gtk-4.0/cityrep.c routine append_impr_or_unit_to_menu_item() does things differently
and is OK as is.

Summary - need to fix the alien ruleset problem because it's part of the official distribution. Need to fix problems with leader name and city name because any user could enter a string with & for those. Nice but not as necessary to fix problems with custom rulesets/scenarios. This patch does fix some problems with unit name and improvement name, but there are unknowns.

Actions #2

Updated by Dean Brown 17 days ago

Patch OK for branches S3_3 and Main.
Could change Target version to 3.2.2

Actions

Also available in: Atom PDF