GNOME Bugzilla – Bug 752920
GtkLabel's warnings when parsing the markup failed are unhelpful
Last modified: 2015-08-03 09:32:36 UTC
Created attachment 308212 [details] [review] GtkLabel: Show erroneous text if parsing markup failed So since I'm displaying random text I get from some webserver, I often run into issues because of non-escaped ampersand characters. GtkLabel prints warnings in this case, but I show many of them so I never know where the warnings come from. It would be helpful if the warnings just included the text that it was trying to set.
Are you using g_markup_escape_text on your random text and still get non-escaped ampersands ? In that case, having some test cases would be nice.
No, I just replace & with &, but I forget it now and then and int that case seeing which label causes the warning is helpful. The fact that ampersands need to be double-escaped in link titles (i.e. tooltips) doesn't really help -- they show up fine but still cause the warning to be printed. I'm not sure if the latter can be fixed in a backwards-compatible way, but I think printing the string is still helpful in any case. Actually, we might just use gtk_tooltip_set_text instead of _set_markup in https://git.gnome.org/browse/gtk+/tree/gtk/gtklabel.c#n6855, since the link title can never contain markup on its own? Or is that wanted so you can set title="<b>bold text</b>"?
The only thing I'm slightly worried about with the patch is that the string might not even be valid utf8, but maybe thats unfounded.
IIRC invalid utf8 will be printed to the console just fine? I don't know if there's another warning for it but if not, printing the text would be helpful as well imo. I just checked that using gtk_tooltip_set_text instead of _set_markup fixes the double-escape problem, but it breaks existing users that double-escaped their stuff of course :/
Review of attachment 308212 [details] [review]: lets go with this, then
Pushed as 61ba7adfc8f1b3ec9ea8deb25d63ca5898f6559c. Thanks!