Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_json does not properly escape values with single quotes #1823

Open
C-Loftus opened this issue Oct 1, 2024 · 0 comments
Open

to_json does not properly escape values with single quotes #1823

C-Loftus opened this issue Oct 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@C-Loftus
Copy link
Contributor

C-Loftus commented Oct 1, 2024

Description

If a json key has a single quote, when it is serialized by pygeoapi's to_json custom jinja filter, it is not escaped correctly and thus causes a syntax error if it is passed into other functions expecting json.

I came across this when rendering covjson data with displayCovJSON(JSON.parse('{{ data | to_json | safe }}'), { display: true })

Steps to Reproduce

  • query an endpoint which returns covjson
  • make sure there is a key containing a single quote
    • i.e. say that the following key is part of the covjson output. Note the word its' in the description below
 "17":{
            "type":"Parameter",
            "description":{
                "en":"Average daily lake/reservoir spillway release in cubic feet per second (cfs). Lake/reservoir spillway release refers to water released from a reservoir via its' spillway structure(s) (typically open channels)."
            },
            "unit":{
                "symbol":"cfs"
            },
            "observedProperty":{
                "id":"17",
                "label":{
                    "en":"Lake/Reservoir Release - Spillway"
                }
            }
        },
  • try to render the covjson leaflet map
  • it should fail to render the map

Expected behavior

If I used the built in json filter: tojson instead of the custom one to_json, it works and escapes the character correctly. I expected to_json to have this same behavior, but also encode time as it is intended to.

Environment

  • OS: MacOS Sonoma 14.3
  • Python version: 3.10
  • pygeoapi version: 0.19.dev0

Additional context

I ensured the returned covjson is valid and if I query with f=json and paste it into the covjson playground, it is valid

Image below shows the invalid json string inside of displayCovJSON(JSON.parse('{{ data | to_json | safe }}'), { display: true })

image

image

@C-Loftus C-Loftus added the bug Something isn't working label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant