Search code examples
javascriptgeoserver

Geoserver cql filter, closing single quote in URL is not read


I got a very strange behavior when using CQL filter. Here's the URL result when using AJAX

http://localhost/geoserver/visualization/ows?service=WFS&version=1.1.0&request=GetFeature&typeName=visualization:pothole,visualization:HPMS&outputFormat=text/javascript&format_options=callback:loadFeatures&srsname=EPSG:3857&cql_filter=branchCode='N00225' AND direction='S'

Now look at below image, it is the above URL displayed in console log.

enter image description here

Notice that the URL breaks after cql_filter=branchCode='N00225 , it doesn't read the closing '. If I click on the URL it will give me this error :

<ows:ExceptionText>Could not parse CQL filter list. Lexical error at line 1, column 19. Encountered: <EOF> after : "\'N00225" Parsing : branchCode='N00225.</ows:ExceptionText>

Here's my javascript code to produce the branchCode above

"branchCode='"+val+"'";

What is the reason behind this and how to solve it?


Solution

  • I'm not sure why, but if I modify my cql filter string like this, it works

    filter = filter.replace(/'/g, '%27').replace(/ /g, '%20');