Skip to content

Commit

Permalink
bugfix: Regex removing all special characters (#9)
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
ftonato committed Jun 24, 2022
1 parent 86f8313 commit d20c15e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion __tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Utils class', () => {
expect(utils.findForbiddenWords(post)).toMatchObject({post, error: null});
});

test.skip('it should return a list of used words filtered by valid characters', () => {
test('it should return a list of used words filtered by valid characters', () => {
const post = `Hello, do you know some forbidden words?
Take a look in our list: (ad-man), black-list, whitelist, {---}, hello_world, FIANCÉE, bOy.!
[BYe]
Expand Down
4 changes: 2 additions & 2 deletions src/suggestions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const roles = {
man_woman: [
{
words: ['ad-man', 'ad-woman'],
words: ['ad-man', 'ad-woman', 'adman', 'adwoman'],
suggestion: 'ad-person',
others: 'advertising executive, promoter',
},
Expand Down Expand Up @@ -529,7 +529,7 @@ const roles = {
],
technology: [
{
words: ['white-list', 'black-list'],
words: ['white-list', 'black-list', 'whitelist', 'blacklist'],
suggestion: 'accept/reject list',
others: 'include/exclude, allow/disallow',
},
Expand Down
11 changes: 9 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ export default class Utils {
}

static getWords(post) {
const regex = /[^a-z0-9]/gi;
/**
* \w Word = Matches any word character (alphanumeric & underscore)
* \- Escaped character = Matches a "-" character (char code 45)
* À-ú Range = Matches a character in the range "À" to "ú"
* (char code 192 to 250). Case sensitive
*/
const regex = /[^\w\-À-ú]+/gi;

const words = post.split(regex);
return words.filter(word => word.toLowerCase()).filter(word => word.length > 0);
return words.filter(word => word.toLowerCase()).filter(word => word.length > 1);
}

findForbiddenWords(post) {
Expand Down

0 comments on commit d20c15e

Please sign in to comment.