Import helper: Improve error messages of non-matching presets; fix bug if a value is 'null' in source geojson

This commit is contained in:
Pieter Vander Vennet 2022-04-04 04:54:54 +02:00
parent 74f00b333b
commit b119e1ac1d
13 changed files with 131 additions and 53 deletions

View file

@ -148,12 +148,6 @@ export class And extends TagsFilter {
return result;
}
AsJson() {
return {
and: this.and.map(a => a.AsJson())
}
}
optimize(): TagsFilter | boolean {
if(this.and.length === 0){
return true

View file

@ -85,12 +85,6 @@ export class Or extends TagsFilter {
return result;
}
AsJson() {
return {
or: this.or.map(o => o.AsJson())
}
}
optimize(): TagsFilter | boolean {
if(this.or.length === 0){

View file

@ -167,6 +167,34 @@ export class TagUtils {
return new Tag(tag[0], tag[1]);
}
/**
* Returns wether or not a keys is (probably) a valid key.
*
* // should accept common keys
* TagUtils.isValidKey("name") // => true
* TagUtils.isValidKey("image:0") // => true
* TagUtils.isValidKey("alt_name") // => true
*
* // should refuse short keys
* TagUtils.isValidKey("x") // => false
* TagUtils.isValidKey("xy") // => false
*
* // should refuse a string with >255 characters
* let a255 = ""
* for(let i = 0; i < 255; i++) { a255 += "a"; }
* a255.length // => 255
* TagUtils.isValidKey(a255) // => true
* TagUtils.isValidKey("a"+a255) // => false
*
* // Should refuse unexpected characters
* TagUtils.isValidKey("with space") // => false
* TagUtils.isValidKey("some$type") // => false
* TagUtils.isValidKey("_name") // => false
*/
public static isValidKey(key: string): boolean {
return key.match(/^[a-z][a-z0-9:_]{2,253}[a-z0-9]$/) !== null
}
/**
* Parses a tag configuration (a json) into a TagsFilter
*

View file

@ -26,8 +26,6 @@ export abstract class TagsFilter {
*/
abstract asChange(properties: any): { k: string, v: string }[]
abstract AsJson() ;
/**
* Returns an optimized version (or self) of this tagsFilter
*/

View file

@ -91,8 +91,10 @@ export class QueryParameters {
parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(QueryParameters.knownSources[key].data))
}
// Don't pollute the history every time a parameter changes
history.replaceState(null, "", "?" + parts.join("&") + Hash.Current());
if(!Utils.runningFromConsole){
// Don't pollute the history every time a parameter changes
history.replaceState(null, "", "?" + parts.join("&") + Hash.Current());
}
}
}