Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/util/xml-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,38 @@ const xmlEscape = function (unsafe) {
// See #1030
unsafe = String(unsafe);
} else {
log.error(`Unexptected type ${typeof unsafe} in xmlEscape at: ${new Error().stack}`);
log.error(`Unexpected type ${typeof unsafe} in xmlEscape at: ${new Error().stack}`);
return unsafe;
}
}
return unsafe.replace(/[<>&'"]/g, c => {
let safe = [];

let i = 0;

while (true) {
const charCode = unsafe.charCodeAt(i);
if (isNaN(charCode)) break;
if (!(
(charCode < 0x20 && charCode !== 0x09 && charCode !== 0x0A && charCode !== 0x0D) ||
(charCode > 0xD7FF && charCode < 0xE000) ||
(charCode > 0xFFFD))
) {
safe.push(charCode);
} else {
safe.push('H'.charCodeAt(0)) // ugly fix

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of these visible? If not then maybe don't push here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are visible characters. It can be triggered by inputting the corresponding character as a variable name, costume name, etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if it's ugly, then wouldn't it be better to have them not show up at all?

}
i++;
}

safe = String.fromCharCode(...safe);

return safe.replace(/[<>&'"]/g, c => {
switch (c) {
case '<': return '&lt;';
case '>': return '&gt;';
case '&': return '&amp;';
case '\'': return '&apos;';
case '"': return '&quot;';
case '<': return '&lt;';
case '>': return '&gt;';
case '&': return '&amp;';
case '\'': return '&apos;';
case '"': return '&quot;';
}
});
};
Expand Down