File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -53,9 +53,11 @@ class Filter {
53
53
* @param {string } string - Sentence to filter.
54
54
*/
55
55
clean ( string ) {
56
+ const joinMatch = this . splitRegex . exec ( string ) ;
57
+ const joinString = ( joinMatch && joinMatch [ 0 ] ) || '' ;
56
58
return string . split ( this . splitRegex ) . map ( ( word ) => {
57
59
return this . isProfane ( word ) ? this . replaceWord ( word ) : word ;
58
- } ) . join ( this . splitRegex . exec ( string ) [ 0 ] ) ;
60
+ } ) . join ( joinString ) ;
59
61
}
60
62
61
63
/**
@@ -85,4 +87,4 @@ class Filter {
85
87
}
86
88
}
87
89
88
- module . exports = Filter ;
90
+ module . exports = Filter ;
Original file line number Diff line number Diff line change @@ -38,10 +38,16 @@ describe('filter', function(){
38
38
39
39
xit ( 'Should filter words that are derivatives of words from the filter blacklist' , function ( ) {
40
40
assert ( filter . clean ( 'shitshit' ) === '********' ) ;
41
- } ) ;
41
+ } ) ;
42
42
43
- it ( 'Shouldn\'t filter words that aren\'t profane.' , function ( ) {
43
+ it ( 'Shouldn\'t filter words that aren\'t profane.' , function ( ) {
44
44
assert ( filter . clean ( 'hello there' ) === 'hello there' ) ;
45
- } ) ;
45
+ } ) ;
46
+
47
+ it ( 'Should handle strings with no word boundaries' , function ( ) {
48
+ assert ( filter . clean ( '' ) === '' ) ;
49
+ assert ( filter . clean ( '.' ) === '.' ) ;
50
+ assert ( filter . clean ( '🙂' ) === '🙂' ) ;
51
+ } ) ;
46
52
} ) ;
47
- } ) ;
53
+ } ) ;
You can’t perform that action at this time.
0 commit comments