Skip to content

Commit

Permalink
don't escape search input for regex
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jamesadney committed Feb 7, 2022
1 parent e9312b0 commit 0d32a81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
38 changes: 20 additions & 18 deletions __test__/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,22 +196,24 @@ describe('Search', function () {
})
})

//
// describe('Special characters', function() {
// it('should escape and handle special characters', function() {
// list.add([
// { name: 'Jonny&Jabba' },
// { name: '<Leia' },
// { name: '>Luke' },
// { name: '"Chewie"' },
// { name: "'Ewok'" }
// ]);
// var result = list.search('Leia');
// console.log(result);
// expect(result.length).toEqual(1);
// var result = list.search('<');
// console.log(result);
// expect(result.length).toEqual(1);
// });
// });
describe('Special characters', function() {
it('should escape and handle special characters', function() {
list.add([
{ name: 'Jonny Jr.' },
{ name: 'Jonny&Jabba' },
{ name: '<Leia' },
{ name: '>Luke' },
{ name: '"Chewie"' },
{ name: "'Ewok'" }
]);
var result = list.search('Leia');
expect(result.length).toEqual(1);

var result = list.search('<');
expect(result.length).toEqual(1);

var result = list.search('Jr.');
expect(result.length).toEqual(1);
});
});
})
1 change: 0 additions & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = function (list) {
},
setSearchString: function (s) {
s = list.utils.toString(s).toLowerCase()
s = s.replace(/[-[\]{}()*+?.,\\^$|#]/g, '\\$&') // Escape regular expression characters
searchString = s
},
toArray: function (values) {
Expand Down

0 comments on commit 0d32a81

Please sign in to comment.