mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Handle leading zeros in quote html entity (#4623)
This commit is contained in:
@@ -26,6 +26,12 @@ describe('unescape', function() {
|
|||||||
assert.strictEqual(unescape(escape(unescaped)), unescaped);
|
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) {
|
lodashStable.each(['`', '/'], function(entity) {
|
||||||
it('should not unescape the "' + entity + '" entity', function() {
|
it('should not unescape the "' + entity + '" entity', function() {
|
||||||
assert.strictEqual(unescape(entity), entity);
|
assert.strictEqual(unescape(entity), entity);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const htmlUnescapes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Used to match HTML entities and HTML characters. */
|
/** 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)
|
const reHasEscapedHtml = RegExp(reEscapedHtml.source)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +31,7 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source)
|
|||||||
*/
|
*/
|
||||||
function unescape(string) {
|
function unescape(string) {
|
||||||
return (string && reHasEscapedHtml.test(string))
|
return (string && reHasEscapedHtml.test(string))
|
||||||
? string.replace(reEscapedHtml, (entity) => htmlUnescapes[entity])
|
? string.replace(reEscapedHtml, (entity) => (htmlUnescapes[entity] || "'") )
|
||||||
: (string || '')
|
: (string || '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user