Verified Commit f3c80628 authored by ivan tkachenko's avatar ivan tkachenko
Browse files

[applets/pager] Fix HTML sanitizing

Prevents a storm of spam errors like this:

    qt.quick.styledtext: StyledText doesn't support entity "#8212"
parent 18e174a9
Pipeline #201977 canceled with stage
in 4 minutes and 45 seconds
......@@ -78,15 +78,27 @@ MouseArea {
ActivitySwitcher.Backend.toggleActivityManager()
}
function sanitize(input: string): string {
// Based on QQuickStyledTextPrivate::parseEntity
const table = {
'>': '>',
'<': '&lt;',
'&': '&amp;',
"'": '&apos;',
'"': '&quot;',
'\u00a0': '&nbsp;',
};
return input.replace(/[<>&'"\u00a0]/g, c => table[c]);
}
function generateWindowList(windows) {
// if we have 5 windows, we would show "4 and another one" with the
// hint that there's 1 more taking the same amount of space than just showing it
const maximum = windows.length === 5 ? 5 : 4
let text = "<ul><li>"
+ windows.slice(0, maximum).map(title => title.replace(/[^0-9A-Za-z ]/g,
c => "&#" + c.charCodeAt(0) + ";")).join("</li><li>")
+ "</li></ul>";
+ windows.slice(0, maximum).map(sanitize).join("</li><li>")
+ "</li></ul>";
if (windows.length > maximum) {
text += i18np("…and %1 other window", "…and %1 other windows", windows.length - maximum)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment