Skip to content

Commit 0d32a81

Browse files
committed
don't escape search input for regex
The search code used to use 'string'.search which takes regex input. Now it used indexOf, so escaping is unnecessary and causes search to break after on of the special characters is entered. From: javve#721
1 parent e9312b0 commit 0d32a81

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

__test__/search.test.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,24 @@ describe('Search', function () {
196196
})
197197
})
198198

199-
//
200-
// describe('Special characters', function() {
201-
// it('should escape and handle special characters', function() {
202-
// list.add([
203-
// { name: 'Jonny&Jabba' },
204-
// { name: '<Leia' },
205-
// { name: '>Luke' },
206-
// { name: '"Chewie"' },
207-
// { name: "'Ewok'" }
208-
// ]);
209-
// var result = list.search('Leia');
210-
// console.log(result);
211-
// expect(result.length).toEqual(1);
212-
// var result = list.search('<');
213-
// console.log(result);
214-
// expect(result.length).toEqual(1);
215-
// });
216-
// });
199+
describe('Special characters', function() {
200+
it('should escape and handle special characters', function() {
201+
list.add([
202+
{ name: 'Jonny Jr.' },
203+
{ name: 'Jonny&Jabba' },
204+
{ name: '<Leia' },
205+
{ name: '>Luke' },
206+
{ name: '"Chewie"' },
207+
{ name: "'Ewok'" }
208+
]);
209+
var result = list.search('Leia');
210+
expect(result.length).toEqual(1);
211+
212+
var result = list.search('<');
213+
expect(result.length).toEqual(1);
214+
215+
var result = list.search('Jr.');
216+
expect(result.length).toEqual(1);
217+
});
218+
});
217219
})

src/search.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module.exports = function (list) {
2828
},
2929
setSearchString: function (s) {
3030
s = list.utils.toString(s).toLowerCase()
31-
s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&') // Escape regular expression characters
3231
searchString = s
3332
},
3433
toArray: function (values) {

0 commit comments

Comments
 (0)