From 818eea51a65a45a09ad9e9b1b2b53c1b0d909270 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 7 Jun 2022 03:38:13 +0200 Subject: [PATCH] The filter config now refuses regexTags except case-invariant regextags --- Models/ThemeConfig/FilterConfig.ts | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Models/ThemeConfig/FilterConfig.ts b/Models/ThemeConfig/FilterConfig.ts index d226ef729e..40bb2a3d33 100644 --- a/Models/ThemeConfig/FilterConfig.ts +++ b/Models/ThemeConfig/FilterConfig.ts @@ -9,6 +9,7 @@ import {UIEventSource} from "../../Logic/UIEventSource"; import {FilterState} from "../FilteredLayer"; import {QueryParameters} from "../../Logic/Web/QueryParameters"; import {Utils} from "../../Utils"; +import {RegexTag} from "../../Logic/Tags/RegexTag"; export default class FilterConfig { public readonly id: string @@ -29,7 +30,6 @@ export default class FilterConfig { } if (json.id.match(/^[a-zA-Z0-9_-]*$/) === null) { throw `A filter with invalid id was found at ${context}. Ids should only contain letters, numbers or - _` - } if (json.options.map === undefined) { @@ -43,12 +43,13 @@ export default class FilterConfig { option.question, `${ctx}.question` ); - let osmTags = undefined; + let osmTags: undefined | TagsFilter = undefined; if ((option.fields?.length ?? 0) == 0 && option.osmTags !== undefined) { osmTags = TagUtils.Tag( option.osmTags, `${ctx}.osmTags` ); + FilterConfig.validateSearch(osmTags, ctx) } if (question === undefined) { throw `Invalid filter: no question given at ${ctx}` @@ -84,6 +85,10 @@ export default class FilterConfig { throw `Invalid filter: multiple filters are set as default, namely ${i} and ${defaultSelection} at ${context}` } } + + if(option.osmTags !== undefined){ + FilterConfig.validateSearch(TagUtils.Tag(option.osmTags), ctx) + } return {question: question, osmTags: osmTags, fields, originalTagsSpec: option.osmTags}; }); @@ -101,6 +106,26 @@ export default class FilterConfig { } + private static validateSearch(osmTags: TagsFilter, ctx: string){ + osmTags.visit(t => { + if (!(t instanceof RegexTag)) { + return; + } + if(typeof t.value == "string"){ + return; + } + + if(t.value.source == '^..*$' || t.value.source == '^[\\s\\S][\\s\\S]*$' /*Compiled regex with 'm'*/){ + return + } + + if(!t.value.ignoreCase) { + throw `At ${ctx}: The filter for key '${t.key}' uses a regex '${t.value}', but you should use a case invariant regex with ~i~ instead, as search should be case insensitive` + } + + }) + } + public initState(): UIEventSource { function reset(state: FilterState): string {