From a296492bbf162de51467dfb5e430f1df17559b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Bibi=C3=A1n?= Date: Tue, 7 Nov 2023 19:16:49 +0100 Subject: [PATCH 1/3] Add negative lookahead to tokenizer --- src/parser.ts | 2 +- test/parse.test.ts | 18 +++++++++++++++++- test/stringify.test.ts | 8 ++++++++ test/tokenizer.test.ts | 8 ++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 1d160e0..1b4dd99 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -10,7 +10,7 @@ export type Token = { export function tokenizer(f: string): Token[] { const ret: Token[] = []; let rest = f; - const patterns = /^(?:(\s+)|(-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?)|("(?:[^"]|\\.|\n)*")|([[()]|]\.?)|(\w[-\w._:\/%]*))/; + const patterns = /^(?:(\s+)|(-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?(?![-\w._:\/\)\s]))|("(?:[^"]|\\.|\n)*")|([[()]|]\.?)|(\w[-\w._:\/%]*))/; let n; while ((n = patterns.exec(rest))) { if (n[1] || n[0].length === 0) { diff --git a/test/parse.test.ts b/test/parse.test.ts index 2754d7f..3ee0a23 100644 --- a/test/parse.test.ts +++ b/test/parse.test.ts @@ -1,5 +1,5 @@ import { eq, op, pr, and, or, v } from "./test_util"; -import { Filter, parse } from "../src"; +import { Filter, parse, stringify } from "../src"; import { assert } from "chai"; // When modifying or adding to these tests, @@ -267,4 +267,20 @@ describe('parse', () => { eq("name", "xxx")) ); }); + + describe('attrPath start with number', () => { + test('064869bf-be25-466f-803d-004a0540574b eq "bjensen"', eq("064869bf-be25-466f-803d-004a0540574b", "bjensen")); + + it('consistent parse and stringify', () => { + const f : Filter = { + op: 'eq', + attrPath: '064869bf-be25-466f-803d-004a0540574b', + compValue: 'bjensen' + } + const string = stringify(f) + const ff = parse(string) + + assert.deepEqual(f, ff) + }) + }) }); diff --git a/test/stringify.test.ts b/test/stringify.test.ts index f46b686..6075708 100644 --- a/test/stringify.test.ts +++ b/test/stringify.test.ts @@ -253,4 +253,12 @@ describe('stringify', () => { ) ); }); + + it('consistent stringify and parse', () => { + const text = '064869bf-be25-466f-803d-004a0540574b eq "bjensen"' + const f = parse(text) + const string = stringify(f) + + assert.deepEqual(text, string) + }) }); diff --git a/test/tokenizer.test.ts b/test/tokenizer.test.ts index 090f768..87cc42c 100644 --- a/test/tokenizer.test.ts +++ b/test/tokenizer.test.ts @@ -32,6 +32,14 @@ describe("tokenizer", () => { ); }); + it("0Field1 eq -12", () => { + console.log(tokenizer("0Field1 eq -12")) + assert.deepEqual( + [tok("0Field1", "Word"), tok("eq", "Word"), tok("-12", "Number"), EOT], + tokenizer("0Field1 eq -12") + ); + }); + it("sub-attribute after ValPath", () => { assert.deepEqual( tokenizer('emails[type eq "work"].value eq "user@example.com"'), From 460d8eebecaa166a4e55c979059a1d57a71fd52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Bibi=C3=A1n?= <48351452+nachobibian@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:09:12 +0100 Subject: [PATCH 2/3] Update tokenizer.test.ts removed console.log --- test/tokenizer.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/tokenizer.test.ts b/test/tokenizer.test.ts index 87cc42c..f8b93e5 100644 --- a/test/tokenizer.test.ts +++ b/test/tokenizer.test.ts @@ -33,7 +33,6 @@ describe("tokenizer", () => { }); it("0Field1 eq -12", () => { - console.log(tokenizer("0Field1 eq -12")) assert.deepEqual( [tok("0Field1", "Word"), tok("eq", "Word"), tok("-12", "Number"), EOT], tokenizer("0Field1 eq -12") From 8bcdc0a3ef1c105e027607a75d979aa1173edaf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nacho=20Bibi=C3=A1n?= Date: Wed, 31 Jan 2024 13:06:55 +0000 Subject: [PATCH 3/3] bump --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 716c128..2c72b44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scim2-parse-filter", - "version": "0.2.8", + "version": "0.2.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scim2-parse-filter", - "version": "0.2.8", + "version": "0.2.10", "license": "Unlicense", "devDependencies": { "@types/chai": "^4.2.12", diff --git a/package.json b/package.json index 43533a2..0ee9ac5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scim2-parse-filter", - "version": "0.2.8", + "version": "0.2.10", "description": "This is a fork https://www.npmjs.com/package/scim2-filter version 0.2.0 with bug correction.", "main": "lib/src/index.js", "directories": {