Skip to content

libnotificationmanager: Escape literal non-tag < chars

Magnus Groß requested to merge vimpostor/plasma-workspace:escapelt into master

If we send a notification that contains a literal "<" in the body, for example:

notify-send "Quick math" "1 < 2"

Then the XML reader will choke on that character, since it is not a valid tag. Now the user could fix this by escaping every "<" as "&lt;", but ultimately it is our job to work by default for plainstring bodies, after all our fancy HTML support is only an additional feature. Right now the notification would only show "1 " in the body due to this problem.

To support this, we now use a whitelist of supported HTML tags and automatically escape the < if we do not find it on the whitelist.

Unfortunately this also has a minor sideeffect: Previously, not allowed tags would be omitted transparently from the final notification. Now they will be visible in escaped form (e.g. "<asdf>test</asdf>" will now become visible instead of being removed). But this should be fine since it is probably a less common occurrence than the literal "<" usecase above and it is more important to support all unstyled notifications than it is to omit exotic HTML tags.

Note that it is not sufficient to just escape "<" if it is followed by a space, e.g. the following notification would then still be rendered incorrectly:

notify-send "New mail" "[PATCH] Make <long name> optional for query_command"
Edited by Magnus Groß

Merge request reports