[BasicUI] Replace non printable characters (#2284)

Fix #2250

Non printable characters are replaced by the unicode replacement
character.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
pull/2096/head
lolodomo 2024-01-27 20:58:23 +01:00 committed by GitHub
parent 4864f43326
commit 1966ba3a53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -438,7 +438,9 @@ public abstract class AbstractWidgetRenderer implements WidgetRenderer {
} }
protected String escapeHtml(@Nullable String s) { protected String escapeHtml(@Nullable String s) {
return StringEscapeUtils.escapeHtml4(s); String result = StringEscapeUtils.escapeHtml4(s);
// Also replace non printable characters by the unicode replacement character
return result != null ? result.replaceAll("[\\p{C}]", "\uFFFD") : "";
} }
@Override @Override

View File

@ -2314,10 +2314,13 @@
_t.escapeHtml = function(text) { _t.escapeHtml = function(text) {
var var
escapedText = text, escapedText = text,
nonPrintable = new RegExp(/\p{C}/, "gu"),
escapeTable = [ escapeTable = [
[ /&/g, "&amp;" ], [ /&/g, "&amp;" ],
[ /</g, "&lt;" ], [ /</g, "&lt;" ],
[ />/g, "&gt;" ] [ />/g, "&gt;" ],
[ /"/g, "&quot;" ],
[ nonPrintable, "\uFFFD" ]
]; ];
for (var i = 0; i < escapeTable.length; i++) { for (var i = 0; i < escapeTable.length; i++) {