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


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

  • Make sure to URLEncode a URL before using it - spaces are not a valid character
    – Ian Turton
    Jun 29, 2020 at 7:35

1 Answer 1


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');
  • This can be a very nice solution, Thanks @gameon67 Jul 13, 2020 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.