FIX: Use Map instead of Object for caching (#14887)

Objects have default properties, such as "constructor" that can cause
issues when using similar texts as keys.
This commit is contained in:
Bianca Nenciu 2021-11-12 15:18:07 +02:00 committed by GitHub
parent 904d509cce
commit 32a174d883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -1689,6 +1689,7 @@ var bar = 'bar';
};
assert.cookedOptions("test fun funny", opts, "<p>test times funny</p>");
assert.cookedOptions("constructor", opts, "<p>constructor</p>");
});
test("watched words link", function (assert) {

View File

@ -73,7 +73,7 @@ export function setup(helper) {
return;
}
const cache = {};
const cache = new Map();
md.core.ruler.push("watched-words", (state) => {
for (let j = 0, l = state.tokens.length; j < l; j++) {
@ -153,8 +153,14 @@ export function setup(helper) {
if (currentToken.type === "text") {
const text = currentToken.content;
const matches = (cache[text] =
cache[text] || findAllMatches(text, matchers));
let matches;
if (cache.has(text)) {
matches = cache.get(text);
} else {
matches = findAllMatches(text, matchers);
cache.set(text, matches);
}
// Now split string to nodes
const nodes = [];