-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue: Using /\b/ to split the text is limited to languages using only the 63 characters: ``` a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 _ ``` cf https://stackoverflow.com/a/2449892 For example, in French, the string `je suis français` will be split into `["je", " ", "suis", " ", "fran", "ç", "ais"]` which won't allow to perform the bad-words cleaning. Therefore I added an option `splitRegex` which allow to overwrite the regex used to split.
- Loading branch information
Showing
2 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require('assert'); | ||
var Filter = require('../lib/badwords.js'), | ||
assert = require('better-assert'); | ||
|
||
describe('options', function() { | ||
describe('split regex', function() { | ||
|
||
it('default value', function() { | ||
filter = new Filter(); | ||
filter.addWords('français'); | ||
assert(filter.clean('fucking asshole') == '******* *******'); | ||
assert(filter.clean('mot en français') == 'mot en français'); | ||
}); | ||
|
||
it('override value', function() { | ||
filter = new Filter({splitRegex: / /}); | ||
filter.addWords('français'); | ||
assert(filter.clean('fucking asshole') == '******* *******'); | ||
assert(filter.clean('mot en français') == 'mot en *******'); | ||
}); | ||
|
||
|
||
}); | ||
}); |
1 comment
on commit 6c97852
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This blows up sometimes, since "exec" can return null. Example input: "?"