diff --git a/packages/node/test/selectors.ts b/packages/node/test/selectors.ts index a7b4827..acf40c5 100644 --- a/packages/node/test/selectors.ts +++ b/packages/node/test/selectors.ts @@ -39,6 +39,11 @@ describe("selectors", () => { paths: ["$.a.c.1"], expected: [4], }, + { + value: '{ "a": [ {"b": 1}, {"c": 2} ] }', + paths: ["$.a.0.b"], + expected: [1], + }, ]; testData.forEach(({ value, paths, expected }) => { @@ -53,6 +58,8 @@ describe("selectors", () => { i += 1; }, ); + + expect(i).toEqual(expected.length); }); }); diff --git a/packages/plainjs/dist/deno/tokenparser.ts b/packages/plainjs/dist/deno/tokenparser.ts index 6987caf..69408b3 100644 --- a/packages/plainjs/dist/deno/tokenparser.ts +++ b/packages/plainjs/dist/deno/tokenparser.ts @@ -101,7 +101,7 @@ export default class TokenParser { const selector = path[i]; const key = this.stack[i + 1].key; if (selector === "*") continue; - if (selector !== key) return false; + if (selector !== key?.toString()) return false; } const selector = path[path.length - 1]; diff --git a/packages/plainjs/src/tokenparser.ts b/packages/plainjs/src/tokenparser.ts index 92f921f..4f28335 100644 --- a/packages/plainjs/src/tokenparser.ts +++ b/packages/plainjs/src/tokenparser.ts @@ -101,7 +101,7 @@ export default class TokenParser { const selector = path[i]; const key = this.stack[i + 1].key; if (selector === "*") continue; - if (selector !== key) return false; + if (selector !== key?.toString()) return false; } const selector = path[path.length - 1]; diff --git a/packages/plainjs/test/selectors.ts b/packages/plainjs/test/selectors.ts index a7b4827..acf40c5 100644 --- a/packages/plainjs/test/selectors.ts +++ b/packages/plainjs/test/selectors.ts @@ -39,6 +39,11 @@ describe("selectors", () => { paths: ["$.a.c.1"], expected: [4], }, + { + value: '{ "a": [ {"b": 1}, {"c": 2} ] }', + paths: ["$.a.0.b"], + expected: [1], + }, ]; testData.forEach(({ value, paths, expected }) => { @@ -53,6 +58,8 @@ describe("selectors", () => { i += 1; }, ); + + expect(i).toEqual(expected.length); }); }); diff --git a/packages/whatwg/test/selectors.ts b/packages/whatwg/test/selectors.ts index a7b4827..acf40c5 100644 --- a/packages/whatwg/test/selectors.ts +++ b/packages/whatwg/test/selectors.ts @@ -39,6 +39,11 @@ describe("selectors", () => { paths: ["$.a.c.1"], expected: [4], }, + { + value: '{ "a": [ {"b": 1}, {"c": 2} ] }', + paths: ["$.a.0.b"], + expected: [1], + }, ]; testData.forEach(({ value, paths, expected }) => { @@ -53,6 +58,8 @@ describe("selectors", () => { i += 1; }, ); + + expect(i).toEqual(expected.length); }); });