diff --git a/src/Logic/Tags/Tag.ts b/src/Logic/Tags/Tag.ts index e8439b267..7e0314cac 100644 --- a/src/Logic/Tags/Tag.ts +++ b/src/Logic/Tags/Tag.ts @@ -137,15 +137,13 @@ export class Tag extends TagsFilter { * new Tag("key","value").shadows(new And([new Tag("x","y"), new RegexTag("a","b", true)]) // => false */ shadows(other: TagsFilter): boolean { - if (other["key"] !== this.key) { - return false - } if (other instanceof Tag) { - // Other.key === this.key - return other.value === this.value + return other.key === this.key && other.value === this.value } if (other instanceof RegexTag) { - return other.matchesProperties({ [this.key]: this.value }) + if(other.key === this.key || !other.invert){ + return other.matchesProperties({ [this.key]: this.value }) + } } return false } diff --git a/test/Logic/Tags/OptimizeTags.spec.ts b/test/Logic/Tags/OptimizeTags.spec.ts index 54c8f66d8..6c81ae124 100644 --- a/test/Logic/Tags/OptimizeTags.spec.ts +++ b/test/Logic/Tags/OptimizeTags.spec.ts @@ -181,6 +181,16 @@ describe("Tag optimalization", () => { const q = new And([new Tag("key", "value"), new RegexTag("key", /value/, true)]) expect(q.optimize()).toBe(false) }) + it("should optimize regexes in the key", () => { + const spec = TagUtils.Tag({ + and: [ + "service:bicycle:retail=yes", + "service:bicycle:.+~~yes" + ] + }) + const tag = spec.optimize() + expect(tag.asJson()).to.eq("service:bicycle:retail=yes") + }) }) describe("Or", () => {