! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
xfce_dialog_show_error() fails to show text containing ampersand
Status:
RESOLVED: FIXED
Product:
Libxfce4ui
Component:
General

Comments

Description Igor editbugs 2016-07-19 16:53:17 CEST
xfce_dialog_show_error() does not show strings containing ampersand chars:

Gtk-WARNING **: Failed to set text '<span weight='bold' size='large'>Failed to open the URL 'news:?xt=13415&amv'</span>' 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 &amp;

The solution would be either to replace ampersand with "&amp;" within xfce_dialog_show_error(), or the caller should do this.
The problem with the second option is that C library does not provide a function to replace string char(s) with other chars; so please consider the first option.
Comment 1 Skunnyk editbugs 2017-11-27 23:22:15 CET
Patches welcome :)
Comment 2 Igor editbugs 2017-11-28 16:40:20 CET
Created attachment 7458 
Escape the text before showing it
Comment 3 Igor editbugs 2017-11-28 16:40:43 CET
Skunnyk, please see attached :)
Comment 4 Skunnyk editbugs 2017-11-28 17:29:33 CET
Hm, I can't reproduce the bug (without the patch):

  xfce_dialog_show_error (NULL, NULL, _("Hey, I'm a & ! "));

It's correctly displayed (tried inside xfburn context). Or maybe it's in another context (markup ?)
Comment 5 Igor editbugs 2017-11-28 23:38:37 CET
The problem is still there for me with the current git version and the URL shown above: "news:?xt=13415&amv".

However, I couldn't reproduce it with the version 4.12.2 which my Ubuntu system has; so please make sure you're testing it against correct version.
Comment 6 Skunnyk editbugs 2017-12-01 14:07:32 CET
Thanks to ochosi, we can use the tests/ inside libxfce4ui to test the behavior (compile with --enable-tests)

I confirm the bug with ./test-ui-gtk3 version, and your patch fix the bug. 
However, this break ./test-ui-gtk2 version, where & are transformed to &amp; . 

Maybe add a #if / #else to support gtk2 and gtk3 ?
The problem is also present in xfce_dialog_show_warning, xfce_dialog_show_info, xfce_dialog_show_info , so create a more generic solution ?
Comment 7 Skunnyk editbugs 2017-12-01 14:10:02 CET
Or fix it directly inside xfce_message_dialog as all xfce_dialog_show_* use this function
Comment 8 Skunnyk editbugs 2017-12-01 17:39:11 CET
Created attachment 7460 
Fix xfce_dialog_message

Proposal to fix xfce_dialog_message for special characters in gtk3 version.
Comment 9 Skunnyk editbugs 2017-12-01 17:50:44 CET
Created attachment 7461 
fix xfce_message_dialog_new_valist

Better fix ! Fix it directly in xfce_message_dialog_new_valist
Comment 10 Igor editbugs 2017-12-01 18:46:50 CET
The patch is almost good, expect for instead of

+      gchar      *escaped_text;
+      /* escape ampersand symbols, etc. (bug #12715) */
+      escaped_text = g_markup_escape_text (primary_text, -1);

it's better to write

+      /* escape ampersand symbols, etc. (bug #12715) */
+      gchar *escaped_text = g_markup_escape_text (primary_text, -1);

in order to avoid "mixed declarations and code" warning.

The patch does not address the case when the text has already been escaped by the caller - in this case, something like "news:?xt=13415&amp;amv" will be shown in the dialog. However, I'm not sure whether this can be addressed at all; and in any case, this is much better than not showing any dialog at all, like it happens now.
Comment 11 Skunnyk editbugs 2017-12-01 21:37:54 CET
Thank you for the review.

I looked in the code for g_markup_escape_text (https://github.com/search?p=1&q=org%3Axfce-mirror+g_markup_escape_text&type=Code), and apart from xfce4-terminal, there is no use of g_markup_escape_text with xfce_dialog-show_*, so the problem should not appear :)
Comment 12 Igor editbugs 2017-12-04 16:16:20 CET
OK, it seems I can use LIBXFCE4UI_CHECK_VERSION() to only escape text when libxfce4ui does not do it.

How about merging the patch then?
Comment 13 Git Bot editbugs 2017-12-05 14:20:18 CET
Romain B referenced this bugreport in commit 8c99d266d7a9b0b09b1dc52df9c5bca2e812247c

Allows to properly show some characters, such as ampersand.

https://git.xfce.org/xfce/libxfce4ui/commit?id=8c99d266d7a9b0b09b1dc52df9c5bca2e812247c
Comment 14 Skunnyk editbugs 2017-12-05 14:20:41 CET
Et voilà :)
Comment 15 Igor editbugs 2017-12-05 14:24:23 CET
Thank you!

The status should become "fixed" now, right?
Comment 16 Skunnyk editbugs 2017-12-05 14:32:36 CET
Done
Comment 17 Skunnyk editbugs 2017-12-05 14:32:51 CET
Rha, stupid bz.
Comment 18 Git Bot editbugs 2017-12-05 16:02:59 CET
Igor referenced this bugreport in commit c563e646de402d628bee2de85aa5de9fea56f36d

Do not escape URL as libxfce4ui now does it

https://git.xfce.org/apps/xfce4-terminal/commit?id=c563e646de402d628bee2de85aa5de9fea56f36d

Bug #12715

Reported by:
Igor
Reported on: 2016-07-19
Last modified on: 2017-12-05

People

Assignee:
Skunnyk
CC List:
4 users

Version

Version:
4.13.0

Attachments

Additional information