Skip to content

Commit 0c168af

Browse files
authored
fix(custom): ignore prototype properties in British English replacement rules (@byseif21) (#7317)
### Description * custom mode (with british english enabled) could break with some words that matched an inherited JS object property, causing crashes * made the replacement logic now ignores prototype property names on the rules object, added a small test for it. Closes #7316
1 parent a4b6671 commit 0c168af

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

frontend/__tests__/test/british-english.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,10 @@ describe("british-english", () => {
6363
await expect(replace("'hello'", "")).resolves.toEqual("'hello'");
6464
await expect(replace("test", "")).resolves.toEqual("test");
6565
});
66+
67+
it("ignores prototype-related property names (e.g. constructor, __proto__)", async () => {
68+
await expect(replace("constructor", "")).resolves.toEqual("constructor");
69+
await expect(replace("__proto__", "")).resolves.toEqual("__proto__");
70+
});
6671
});
6772
});

frontend/src/ts/test/british-english.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ export async function replace(
700700
).join("-");
701701
} else {
702702
const cleanedWord = word.replace(/^[\W]+|[\W]+$/g, "").toLowerCase();
703+
if (!Object.prototype.hasOwnProperty.call(replacementRules, cleanedWord)) {
704+
return word;
705+
}
703706
const rule = replacementRules[cleanedWord];
704707

705708
if (rule === undefined) return word;

0 commit comments

Comments
 (0)