Skip to content

Commit b530da1

Browse files
authored
🔀 Merge pull request #538 from FrostCo/fix_remove_special_characters
Fix special characters for remove filter mode
2 parents 5802211 + 221d155 commit b530da1

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

src/script/lib/word.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class Word {
1515
unicode: boolean;
1616
value: string;
1717

18-
private static readonly _edgePunctuationRegExp = /(^[,.'"!?%$+]|[,.'"!?%$+]$)/;
18+
private static readonly _edgePunctuationRegExp = /(^[,.'"`!@#$%^&*?:;+~_=()[\]{}<>|\\/-]|[,.'"`!@#$%^&*?:;+~_=()[\]{}<>|\\/-]$)/;
1919
private static readonly _escapeRegExp = /[\/\\^$*+?.()|[\]{}]/g;
2020
private static readonly _unicodeRegExp = /[^\u0000-\u00ff]/;
2121
private static readonly _unicodeWordBoundary = '[\\s.,\'"+!?|-]';

test/spec/lib/filter.spec.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ describe('Filter', () => {
134134
filter.init();
135135
expect(filter.replaceText('You deserve an A+')).to.equal('You deserve an __');
136136
});
137+
138+
it('Ending with tilde', () => {
139+
const filter = new Filter;
140+
filter.cfg = new Config({
141+
censorCharacter: '_',
142+
filterMethod: Constants.FILTER_METHODS.CENSOR,
143+
preserveFirst: false,
144+
words: {
145+
'waves~': { matchMethod: Constants.MATCH_METHODS.EXACT },
146+
},
147+
});
148+
filter.init();
149+
expect(filter.replaceText('Look at those waves~')).to.equal('Look at those ______');
150+
});
137151
});
138152

139153
describe('Partial', () => {
@@ -186,6 +200,22 @@ describe('Filter', () => {
186200
expect(filter.replaceText('I love allthis! Do you?')).to.equal('I love all_____ Do you?');
187201
expect(filter.replaceText('I love this! Do you?')).to.equal('I love _____ Do you?');
188202
});
203+
204+
it('Ending with brackets and braces', () => {
205+
const filter = new Filter;
206+
filter.cfg = new Config({
207+
censorCharacter: '_',
208+
filterMethod: Constants.FILTER_METHODS.CENSOR,
209+
preserveFirst: false,
210+
words:{
211+
'{cool}': { matchMethod: Constants.MATCH_METHODS.PARTIAL },
212+
'[tag]': { matchMethod: Constants.MATCH_METHODS.PARTIAL },
213+
},
214+
});
215+
filter.init();
216+
expect(filter.replaceText('Check the [tag] for the sale')).to.equal('Check the _____ for the sale');
217+
expect(filter.replaceText('You are so {cool}!')).to.equal('You are so ______!');
218+
});
189219
});
190220

191221
describe('Whole', () => {
@@ -832,6 +862,19 @@ describe('Filter', () => {
832862
expect(filter.replaceText('I love this!')).to.equal('I love');
833863
});
834864

865+
it('Ending with semicolon', () => {
866+
const filter = new Filter;
867+
filter.cfg = new Config({
868+
filterMethod: Constants.FILTER_METHODS.REMOVE,
869+
words: {
870+
'and more;': { matchMethod: Constants.MATCH_METHODS.EXACT, repeat: Constants.FALSE },
871+
},
872+
});
873+
filter.init();
874+
expect(filter.replaceText('and more;')).to.equal('');
875+
expect(filter.replaceText('you can have it all, and more;')).to.equal('you can have it all,');
876+
});
877+
835878
it('With separators', () => {
836879
const filter = new Filter;
837880
filter.cfg = new Config({
@@ -874,6 +917,35 @@ describe('Filter', () => {
874917
expect(filter.replaceText('I love allthis! Do you?')).to.equal('I love Do you?');
875918
expect(filter.replaceText('I love this! Do you?')).to.equal('I love Do you?');
876919
});
920+
921+
it('Ending with colon', () => {
922+
const filter = new Filter;
923+
filter.cfg = new Config({
924+
filterMethod: Constants.FILTER_METHODS.REMOVE,
925+
words: {
926+
'app. rate:': { matchMethod: Constants.MATCH_METHODS.PARTIAL, repeat: Constants.FALSE },
927+
},
928+
});
929+
filter.init();
930+
expect(filter.replaceText('app. rate:')).to.equal('');
931+
expect(filter.replaceText('app. rate: 5.93%')).to.equal('5.93%');
932+
});
933+
934+
it('Ending with special characters', () => {
935+
const filter = new Filter;
936+
filter.cfg = new Config({
937+
filterMethod: Constants.FILTER_METHODS.REMOVE,
938+
words: {
939+
'check-mate/': { matchMethod: Constants.MATCH_METHODS.PARTIAL, repeat: Constants.FALSE },
940+
'cheese()': { matchMethod: Constants.MATCH_METHODS.PARTIAL, repeat: Constants.FALSE },
941+
'{cake': { matchMethod: Constants.MATCH_METHODS.PARTIAL, repeat: Constants.FALSE },
942+
},
943+
});
944+
filter.init();
945+
expect(filter.replaceText('Surprise! Check-mate/')).to.equal('Surprise!');
946+
expect(filter.replaceText('Say cheese()')).to.equal('Say');
947+
expect(filter.replaceText('Do you want any {cake')).to.equal('Do you want any');
948+
});
877949
});
878950

879951
it('Should filter a RegExp', () => {

test/spec/lib/word.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ describe('Word', function() {
135135
expect(word.regExp).to.eql(/(^|\s)([\w-]*word![\w-]*)(\s|$)/gi);
136136
});
137137

138+
it('should build RegExp with ending colon', function() {
139+
const word = new Word('app. rate:', { matchMethod: Constants.MATCH_METHODS.PARTIAL }, Object.assign(Config._defaults, { filterMethod: Constants.FILTER_METHODS.REMOVE }));
140+
expect(word.regExp).to.eql(/(^|\s)([\w-]*app\. rate:[\w-]*)(\s|$)/gi);
141+
});
142+
138143
// Work around for lack of word boundary support for unicode characters
139144
describe('Unicode', function() {
140145
it('should build RegExp', function() {

0 commit comments

Comments
 (0)