Skip to content

Quote Search strings as JSON - #2357

Open
KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:search-quote-strings
Open

KhadeerBasha1232 wants to merge 1 commit into
python-visualization:mainfrom
KhadeerBasha1232:search-quote-strings

Conversation

@KhadeerBasha1232

Copy link
Copy Markdown
Contributor

Quote Search strings as JSON

Search put search_label, placeholder and position inside single quotes in the generated JavaScript, without escaping them. A value with an apostrophe breaks the script:

import folium
from folium.plugins import Search

m = folium.Map()
layer = folium.GeoJson(data).add_to(m)
Search(layer, search_label="name", placeholder="Search for a state's name").add_to(m)

This renders textPlaceholder: 'Search for a state's name',, which is a SyntaxError (Unexpected identifier 's'). Nothing in the map script runs, so the page is blank. The same happens for a property name that contains an apostrophe.

I checked this in a browser: before the change the page is blank, and after it the map and search box show up with the placeholder Search for a state's name.

Change

These three values are now rendered with the tojson filter, the same way collapsed already is. tojson also escapes <, >, & and ', so the values are safe inside the <script> block.

Tests

test_search_quotes_strings checks that search_label and placeholder are rendered as valid JS strings when they contain an apostrophe. It fails without the change.

Search put search_label, placeholder and position inside single quotes
without escaping them, so a value with an apostrophe, such as
placeholder="Search for a state's name", produced a JavaScript syntax
error and the whole map script failed to run.

Render these values with the tojson filter instead.

This branch was previously deployed

1 inactive deployment
pypi — b895905e Deployed Nov 19, 2026 by KhadeerBasha1232 via packages #2111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant