diff --git a/src/internal/filters.ts b/src/internal/filters.ts index e3d4353..546979a 100644 --- a/src/internal/filters.ts +++ b/src/internal/filters.ts @@ -12,7 +12,7 @@ export function FilterValuesOf(filter: FieldFilter): FilterValue[] { } export function parseFilter(searchVal: string): FilterValue { - const match = searchVal.match(/([^:]+):(.*)/); + const match = searchVal.match(/^:*([^:]+):(.*)/); return match ? [match[2], match[1]] : [searchVal, "eq"]; } diff --git a/src/tests/components/filter_comparisons.test.ts b/src/tests/components/filter_comparisons.test.ts index 5a205e0..3da91e3 100644 --- a/src/tests/components/filter_comparisons.test.ts +++ b/src/tests/components/filter_comparisons.test.ts @@ -60,4 +60,21 @@ describe("Parameters.ExtractFilters - comparisons", () => { ), ).to.eql({ title: ["//example.com", "http"] }); }); + + it("reads the comparison after the colons a value opens with", () => { + expect( + Parameters.ExtractFilters(context("filter_title=::is:abc"), meta), + ).to.eql({ title: ["abc", "is"] }); + }); + + it("reads a long value without a colon in linear time", () => { + const value = "a".repeat(64_000); + const start = performance.now(); + const filters = Parameters.ExtractFilters( + context(`filter_title=${value}`), + meta, + ); + expect(performance.now() - start).to.be.below(250); + expect(filters).to.eql({ title: [value, "eq"] }); + }); });