diff options
| author | supahgreg <supahgreg@users.noreply.github.com> | 2025-10-10 22:39:31 +0000 |
|---|---|---|
| committer | supahgreg <supahgreg@users.noreply.github.com> | 2025-10-10 22:39:47 +0000 |
| commit | b888fa10328219d4eb5bec3fd0c69fa859a8c43b (patch) | |
| tree | f87c72b435cd9519decba89e2748509f1d08c74c | |
| parent | 26f1f67746850a3806b5f395ada3f478ca2b951b (diff) | |
Fix a potential double-unescaping issue, tweak 'App.escapeHtml()'.
| -rw-r--r-- | js/App.js | 38 | ||||
| -rwxr-xr-x | js/FeedTree.js | 11 |
2 files changed, 28 insertions, 21 deletions
@@ -411,19 +411,35 @@ const App = { }, // htmlspecialchars()-alike for headlines data-content attribute escapeHtml: function(p) { - if (typeof p == "string") { - const map = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''' - }; + if (typeof p !== 'string') + return p; - return p.replace(/[&<>"']/g, function(m) { return map[m]; }); - } else { + const map = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + '/': '/', + }; + + return p.replace(/[&<>"'\/]/g, m => map[m]); + }, + unescapeHtml: function(p) { + if (typeof p !== 'string' || p.indexOf('&') === -1) return p; - } + + return p.replace(/&(?:amp|lt|gt|quot|#x27|#x2F|#039|#47);/g, function(entity) { + switch (entity) { + case '&': return '&'; + case '<': return '<'; + case '>': return '>'; + case '"': return '"'; + case ''': case ''': return "'"; + case '/': case '/': return '/'; + default: return entity; + } + }); }, // http://stackoverflow.com/questions/6251937/how-to-get-selecteduser-highlighted-text-in-contenteditable-element-and-replac getSelectedText: function() { diff --git a/js/FeedTree.js b/js/FeedTree.js index 67d2a8035..683205579 100755 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -237,16 +237,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co return rc; }, getLabel: function(item) { - let name = String(item.name); - - /* Horrible */ - name = name.replace(/"/g, "\""); - name = name.replace(/&/g, "&"); - name = name.replace(/—/g, "-"); - name = name.replace(/</g, "<"); - name = name.replace(/>/g, ">"); - - return name; + return App.unescapeHtml(item.name); }, expandParentNodes: function(feed, is_cat, list) { try { |