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
This commit is contained in:
Seif Soliman 2026-01-06 17:24:40 +02:00 committed by GitHub
parent a4b6671046
commit 0c168af841
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View file

@ -63,5 +63,10 @@ describe("british-english", () => {
await expect(replace("'hello'", "")).resolves.toEqual("'hello'");
await expect(replace("test", "")).resolves.toEqual("test");
});
it("ignores prototype-related property names (e.g. constructor, __proto__)", async () => {
await expect(replace("constructor", "")).resolves.toEqual("constructor");
await expect(replace("__proto__", "")).resolves.toEqual("__proto__");
});
});
});

View file

@ -700,6 +700,9 @@ export async function replace(
).join("-");
} else {
const cleanedWord = word.replace(/^[\W]+|[\W]+$/g, "").toLowerCase();
if (!Object.prototype.hasOwnProperty.call(replacementRules, cleanedWord)) {
return word;
}
const rule = replacementRules[cleanedWord];
if (rule === undefined) return word;