diff --git a/Logic/Tags/RegexTag.ts b/Logic/Tags/RegexTag.ts index fae2fd70ba..68840188b3 100644 --- a/Logic/Tags/RegexTag.ts +++ b/Logic/Tags/RegexTag.ts @@ -47,6 +47,11 @@ export class RegexTag extends TagsFilter { } matchesProperties(tags: any): boolean { + if(typeof this.key === "string"){ + const value = tags[this.key] ?? "" + return RegexTag.doesMatch(value, this.value) != this.invert; + } + for (const key in tags) { if (key === undefined) { continue; diff --git a/Logic/Tags/Tag.ts b/Logic/Tags/Tag.ts index 66bb993f93..f2539e1bc6 100644 --- a/Logic/Tags/Tag.ts +++ b/Logic/Tags/Tag.ts @@ -23,26 +23,14 @@ export class Tag extends TagsFilter { matchesProperties(properties: any): boolean { - for (const propertiesKey in properties) { - if (!properties.hasOwnProperty(propertiesKey)) { - continue - } - if (this.key === propertiesKey) { - const value = properties[propertiesKey]; - if (value === undefined) { - continue - } - return value === this.value; - } - } - // The tag was not found - - if (this.value === "") { + const foundValue = properties[this.key] + if (foundValue === undefined && (this.value === "" || this.value === undefined)) { + // The tag was not found // and it shouldn't be found! return true; } - return false; + return foundValue === this.value; } asOverpass(): string[] { diff --git a/test/Tag.spec.ts b/test/Tag.spec.ts index a85d3c58dd..d3ae8b9c65 100644 --- a/test/Tag.spec.ts +++ b/test/Tag.spec.ts @@ -9,6 +9,7 @@ import {Tag} from "../Logic/Tags/Tag"; import {And} from "../Logic/Tags/And"; import {TagUtils} from "../Logic/Tags/TagUtils"; import TagRenderingConfig from "../Models/ThemeConfig/TagRenderingConfig"; +import {RegexTag} from "../Logic/Tags/RegexTag"; Utils.runningFromConsole = true; @@ -173,7 +174,6 @@ export default class TagSpec extends T { equal(undefined, tr.GetRenderValue({"foo": "bar"})); })], - [ "Empty match test", () => { @@ -214,7 +214,8 @@ export default class TagSpec extends T { const overpassOrInor = TagUtils.Tag(orInOr).asOverpass() equal(3, overpassOrInor.length) } - ], [ + ], + [ "Merge touching opening hours", () => { const oh1: OpeningHour = { @@ -239,7 +240,8 @@ export default class TagSpec extends T { equal(r.endHour, 12) } - ], [ + ], + [ "Merge overlapping opening hours", () => { const oh1: OpeningHour = { @@ -394,7 +396,8 @@ export default class TagSpec extends T { ])); equal(rules, "Tu 23:00-00:00"); - }], ["JOIN OH with overflowed hours", () => { + }], + ["JOIN OH with overflowed hours", () => { const rules = OH.ToString( OH.MergeTimes([ @@ -483,7 +486,41 @@ export default class TagSpec extends T { const tagRendering = new TagRenderingConfig(config, null, "test"); equal(true, tagRendering.IsKnown({bottle: "yes"})) equal(false, tagRendering.IsKnown({})) - }]]); + }], + [ + "Tag matches a lazy property", + () => { + const properties = {} + const key = "_key" + Object.defineProperty(properties, key, { + configurable: true, + get: function () { + delete properties[key] + properties[key] = "yes" + return "yes" + } + }) + const filter = new Tag("_key", "yes") + T.isTrue(filter.matchesProperties(properties), "Lazy value not matched") + } + ], + [ + "RegextTag matches a lazy property", + () => { + const properties = {} + const key = "_key" + Object.defineProperty(properties, key, { + configurable: true, + get: function () { + delete properties[key] + properties[key] = "yes" + return "yes" + } + }) + const filter = TagUtils.Tag("_key~*") + T.isTrue(filter.matchesProperties(properties), "Lazy value not matched") + } + ]]); } }