From 8396eac0973b7b586d3e2bf29d0e59ab32e187b3 Mon Sep 17 00:00:00 2001 From: Daniel Spofford Date: Wed, 21 Oct 2015 21:19:26 -0500 Subject: [PATCH] Add tests for quoted search terms with spaces and escaped quotes in them --- test/test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/test.js b/test/test.js index 414ab0b..14385a6 100644 --- a/test/test.js +++ b/test/test.js @@ -201,4 +201,26 @@ describe('Search query syntax parser', function () { }); + it('should not split on spaces inside single and double quotes', function () { + var searchQuery = 'name:"Bob Saget" description:\'Banana Sandwiche\''; + var options = {keywords: ['name', 'description']}; + var parsedSearchQuery = searchquery.parse(searchQuery, options); + + parsedSearchQuery.should.be.an.Object; + parsedSearchQuery.should.have.property('name', 'Bob Saget'); + parsedSearchQuery.should.have.property('description', 'Banana Sandwiche'); + }); + + + it('should correctly handle escaped single and double quotes', function () { + var searchQuery = 'case1:"This \\"is\\" \'a\' test" case2:\'This "is" \\\'a\\\' test\''; + var options = {keywords: ['case1', 'case2']}; + var parsedSearchQuery = searchquery.parse(searchQuery, options); + + parsedSearchQuery.should.be.an.Object; + parsedSearchQuery.should.have.property('case1', 'This "is" \'a\' test'); + parsedSearchQuery.should.have.property('case2', 'This "is" \'a\' test'); + }); + + });