mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 13:09:33 -06:00
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:
parent
904d509cce
commit
32a174d883
@ -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) {
|
||||
|
@ -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 = [];
|
||||
|
Loading…
Reference in New Issue
Block a user