From 7dc9c4c0f5f111a7a06c97e8fb2e964f426f5f58 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 8 Jan 2020 17:31:43 -0600 Subject: [PATCH] Handle leading zeros in quote html entity --- test/unescape.js | 6 ++++++ unescape.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/unescape.js b/test/unescape.js index 418ebdff95..7bd56137f7 100644 --- a/test/unescape.js +++ b/test/unescape.js @@ -26,6 +26,12 @@ describe('unescape', function() { assert.strictEqual(unescape(escape(unescaped)), unescaped); }); + it('should handle leading zeros in html entities', function() { + assert.strictEqual(unescape('''), "'"); + assert.strictEqual(unescape('''), "'"); + assert.strictEqual(unescape('''), "'"); + }); + lodashStable.each(['`', '/'], function(entity) { it('should not unescape the "' + entity + '" entity', function() { assert.strictEqual(unescape(entity), entity); diff --git a/unescape.js b/unescape.js index e05c736088..19abf96a4e 100644 --- a/unescape.js +++ b/unescape.js @@ -8,7 +8,7 @@ const htmlUnescapes = { } /** Used to match HTML entities and HTML characters. */ -const reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g +const reEscapedHtml = /&(?:amp|lt|gt|quot|#(0+)?39);/g const reHasEscapedHtml = RegExp(reEscapedHtml.source) /** @@ -31,7 +31,7 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source) */ function unescape(string) { return (string && reHasEscapedHtml.test(string)) - ? string.replace(reEscapedHtml, (entity) => htmlUnescapes[entity]) + ? string.replace(reEscapedHtml, (entity) => (htmlUnescapes[entity] || "'") ) : (string || '') } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy