geostyler / geostyler-mapfile-parser

GeoStyler Style Parser implementation for MapServer Mapfiles
BSD 2-Clause "Simplified" License
7 stars 5 forks source link

Regular Expressions fail when converted to OpenLayers #247

Closed geographika closed 1 month ago

geographika commented 1 year ago

A class such as in the tests at https://github.com/geostyler/geostyler-mapfile-parser/blob/17c74e1001802891c840c66729f0807a4dfbc412/data/mapfiles/point_st_sample_style_tags_single_filter_list.map#L12

  CLASS
    EXPRESSION {bus,bank}

Converts to the following GeoStyler style https://github.com/geostyler/geostyler-mapfile-parser/blob/17c74e1001802891c840c66729f0807a4dfbc412/data/styles/point_st_sample_style_tags_single_filter_list.ts#L12

    filter: [
      '==', {
        name: 'strMatches',
        args: [{
          name: 'property',
          args: ['name']
        }, '/(bus|bank)/']

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)\//

I presume this is an issue with the mapfile parser rather than the OL parser? How do other parsers store lists for strMatches?

KaiVolland commented 1 month ago

Hey @geographika do you remember if this is fixed with https://github.com/geostyler/geostyler-openlayers-parser/pull/702 ?

geographika commented 1 month ago

@KaiVolland - yes fixed and tested for by that pull request. Closing.