FIX: Correctly censor strings starting or ending with non-word characters (#6445)

This commit is contained in:
David Taylor
2018-10-04 15:15:10 +01:00
committed by GitHub
parent 361ad7ed2b
commit 3c2608d41c
2 changed files with 26 additions and 9 deletions

View File

@ -16,7 +16,7 @@ const rawOpts = {
enable_markdown_linkify: true,
markdown_linkify_tlds: "com"
},
censoredWords: "shucks|whiz|whizzer|a**le|badword*",
censoredWords: "shucks|whiz|whizzer|a**le|badword*|shuck$|café|$uper",
getURL: url => url
};
@ -959,6 +959,25 @@ QUnit.test("censoring", assert => {
"<p>I have a pen, I have an ■■■■■</p>",
"it escapes regexp chars"
);
assert.cooked(
"Aw shuck$, I can't fix the problem with money",
"<p>Aw ■■■■■■, I can't fix the problem with money</p>",
"it works for words ending in non-word characters"
);
assert.cooked(
"Let's go to a café today",
"<p>Let's go to a ■■■■ today</p>",
"it works for words ending in accented characters"
);
assert.cooked(
"Discourse is $uper amazing",
"<p>Discourse is ■■■■■ amazing</p>",
"it works for words starting with non-word characters"
);
assert.cooked(
"No badword or apple here plz.",
"<p>No ■■■■■■■ or ■■■■■ here plz.</p>",