Skip to content

Commit 324b15f

Browse files
committed
Fix "quoted values with ':'" scenario
1 parent 51a5a6e commit 324b15f

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const EMPTY_VAL_GROUP = `${VAL_TOKEN}${VAL_TOKEN}`
1010
const KEY_SEPARATOR = '.'
1111
const NEGATED_PREFIX = 'not'
1212
const RANGE_REGEXP = /^[^-\d]*(-?\d+(\.\d+)?)?[^-\d]*-[^-\d]*(-?\d+(\.\d+)?)?[^-\d]*$/
13-
const TOKENIZER = new RegExp(` *(${NEGATED_PREFIX})? *(\\${GROUP_START})| *(${NEGATED_PREFIX} +)?(?:((?:\\\\.|[^ ${GROUP_START}${GROUP_END}\\\\${REGEX_CHAR}${RANGE_CHAR}${TOKEN_SEPARATOR}])+) *([${REGEX_CHAR}${RANGE_CHAR}]?${TOKEN_SEPARATOR}))? *(${VAL_TOKEN}((?:\\\\.|[^${VAL_TOKEN}\\\\])+)${VAL_TOKEN}?|(?:\\\\.|[^ ${GROUP_START}${GROUP_END}\\\\])+)? *(and|or|\\${GROUP_END}|$)`, 'g')
13+
const TOKENIZER = new RegExp(` *(${NEGATED_PREFIX})? *(\\${GROUP_START})| *(${NEGATED_PREFIX} +)?(?:((?:\\\\.|[^ ${GROUP_START}${GROUP_END}\\\\${REGEX_CHAR}${RANGE_CHAR}${VAL_TOKEN}${TOKEN_SEPARATOR}])+) *([${REGEX_CHAR}${RANGE_CHAR}]?${TOKEN_SEPARATOR}))? *(${VAL_TOKEN}((?:\\\\.|[^${VAL_TOKEN}\\\\])+)${VAL_TOKEN}?|(?:\\\\.|[^ ${GROUP_START}${GROUP_END}\\\\])+)? *(and|or|\\${GROUP_END}|$)`, 'g')
1414
const TOKEN = { GROUP_NEGATED: 1, GROUP_START: 2, NEGATED: 3, KEY: 4, TYPE: 5, VALUE: 6, QUOTED_VALUE: 7, OPERATOR: 8 }
1515
const UNKNOWN = -1
1616
const EMPTY_STR = ''

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ecromaneli/search-engine",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "A powerful object search engine with advanced query syntax",
55
"main": "dist/npm/index.min.js",
66
"files": [ "dist/npm/index.min.*", "dist/npm/index.d.*", "LICENSE" ],

test/index.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('Search Engine', () => {
1111
tags: ["developer", "javascript"],
1212
contact: {
1313
email: "john.smith@example.com",
14-
phone: "555-1234"
14+
phone: "555-1234",
15+
website: "https://example.com",
1516
}
1617
},
1718
{
@@ -371,6 +372,11 @@ describe('Search Engine', () => {
371372
expect(results.length).toBe(2)
372373
expect(results[0].id).toBe(1)
373374
expect(results[1].id).toBe(2)
375+
376+
query = '"John Smith" and "https:'
377+
results = Search.search(testData, query)
378+
expect(results.length).toBe(1)
379+
expect(results[0].id).toBe(1)
374380
})
375381

376382
test('Empty partially quoted values', () => {

0 commit comments

Comments
 (0)