Skip to content

Commit d20c15e

Browse files
authored
bugfix: Regex removing all special characters (#9)
Closes #5
1 parent 86f8313 commit d20c15e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

__tests__/utils.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Utils class', () => {
1010
expect(utils.findForbiddenWords(post)).toMatchObject({post, error: null});
1111
});
1212

13-
test.skip('it should return a list of used words filtered by valid characters', () => {
13+
test('it should return a list of used words filtered by valid characters', () => {
1414
const post = `Hello, do you know some forbidden words?
1515
Take a look in our list: (ad-man), black-list, whitelist, {---}, hello_world, FIANCÉE, bOy.!
1616
[BYe]

src/suggestions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const roles = {
22
man_woman: [
33
{
4-
words: ['ad-man', 'ad-woman'],
4+
words: ['ad-man', 'ad-woman', 'adman', 'adwoman'],
55
suggestion: 'ad-person',
66
others: 'advertising executive, promoter',
77
},
@@ -529,7 +529,7 @@ const roles = {
529529
],
530530
technology: [
531531
{
532-
words: ['white-list', 'black-list'],
532+
words: ['white-list', 'black-list', 'whitelist', 'blacklist'],
533533
suggestion: 'accept/reject list',
534534
others: 'include/exclude, allow/disallow',
535535
},

src/utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,16 @@ export default class Utils {
2525
}
2626

2727
static getWords(post) {
28-
const regex = /[^a-z0-9]/gi;
28+
/**
29+
* \w Word = Matches any word character (alphanumeric & underscore)
30+
* \- Escaped character = Matches a "-" character (char code 45)
31+
* À-ú Range = Matches a character in the range "À" to "ú"
32+
* (char code 192 to 250). Case sensitive
33+
*/
34+
const regex = /[^\w\-À-ú]+/gi;
35+
2936
const words = post.split(regex);
30-
return words.filter(word => word.toLowerCase()).filter(word => word.length > 0);
37+
return words.filter(word => word.toLowerCase()).filter(word => word.length > 1);
3138
}
3239

3340
findForbiddenWords(post) {

0 commit comments

Comments
 (0)