diff --git a/app/assets/javascripts/pretty-text/censored-words.js.es6 b/app/assets/javascripts/pretty-text/censored-words.js.es6 index badaeb322cc..32c21dc39b6 100644 --- a/app/assets/javascripts/pretty-text/censored-words.js.es6 +++ b/app/assets/javascripts/pretty-text/censored-words.js.es6 @@ -2,6 +2,10 @@ function escapeRegexp(text) { return text.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&").replace(/\*/g, "S*"); } +function createCensorRegexp(patterns) { + return new RegExp(`((? url }; @@ -959,6 +959,25 @@ QUnit.test("censoring", assert => { "
I have a pen, I have an ■■■■■
", "it escapes regexp chars" ); + + assert.cooked( + "Aw shuck$, I can't fix the problem with money", + "Aw ■■■■■■, I can't fix the problem with money
", + "it works for words ending in non-word characters" + ); + + assert.cooked( + "Let's go to a café today", + "Let's go to a ■■■■ today
", + "it works for words ending in accented characters" + ); + + assert.cooked( + "Discourse is $uper amazing", + "Discourse is ■■■■■ amazing
", + "it works for words starting with non-word characters" + ); + assert.cooked( "No badword or apple here plz.", "No ■■■■■■■ or ■■■■■ here plz.
",