Skip to content

Escape dictionary words before using them in regular expressions - #40

Open
samipuro wants to merge 1 commit into
ConsoleTVs:masterfrom
samipuro:fix/escape-dictionary-words
Open

samipuro wants to merge 1 commit into
ConsoleTVs:masterfrom
samipuro:fix/escape-dictionary-words

Conversation

@samipuro

Copy link
Copy Markdown

Dictionary words are inserted into the regex without escaping, so any word containing regex characters matches the wrong text. With a custom dictionary containing "13". and "c++", the text "I paid 139 euros, c++ rocks" is filtered to "I paid *** euros, ***++ rocks".

This adds a small wordPattern() helper that runs preg_quote() on the word. badWords() and filter() both use it, which also removes the duplicated strict/non-strict branches.

Checked the shipped Default.json: the output of badWords() and filter() is byte-for-byte identical before and after for all 2554 words, so only custom dictionaries are affected. Related to #19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant