When this is converted to an OpenLayers style function using the code in OlStyleUtil
case 'strMatches':
return new RegExp(args[1] as string).test(args[0] as string);
The forward slashes are escaped and no features are matched:
r = new RegExp(args[1])
/\/(bus|bank)\//
// this is what we want
r = new RegExp(/(bus|bank)/)
/(bus|bank)/
// but as a string is passed they are escaped:
r = new RegExp('/(bus|bank)/')
/\/(bus|bank)\//
This pull request strips the start and trailing '\' from the string. As discussed with @jansule there may be issues if flags are stored in GeoStyler regex strings e.g. /pattern/gmi. To support this requires passing 'gmi' to the flags parameter of the RegEx constructor e.g. new RegExp('pattern', 'gmi'). This is handled in this pull request.
The following approach works for all cases r = new RegExp(eval(args[1])) but using eval is problematic.
Initially I thought String.raw was an option but this doesn't work correctly.
Description
A MapServer class such as in the tests here :
Converts to the following GeoStyler style (see here):
When this is converted to an OpenLayers style function using the code in OlStyleUtil
The forward slashes are escaped and no features are matched:
This pull request strips the start and trailing '\' from the string. As discussed with @jansule there may be issues if flags are stored in GeoStyler regex strings e.g.
/pattern/gmi
. To support this requires passing'gmi'
to the flags parameter of the RegEx constructor e.g.new RegExp('pattern', 'gmi')
. This is handled in this pull request.The following approach works for all cases
r = new RegExp(eval(args[1]))
but usingeval
is problematic. Initially I thoughtString.raw
was an option but this doesn't work correctly.Related issues or pull requests
Originally added as an issue at https://github.com/geostyler/geostyler-mapfile-parser/issues/247
Pull request type
Do you introduce a breaking change?
Checklist
npm test
locally)