Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions folium/plugins/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class Search(JSCSSMixin, MacroElement):
var {{this.layer.get_name()}}searchControl = new L.Control.Search({
layer: {{this.layer.get_name()}},
{% if this.search_label %}
propertyName: '{{this.search_label}}',
propertyName: {{ this.search_label|tojson }},
{% endif %}
collapsed: {{this.collapsed|tojson|safe}},
textPlaceholder: '{{this.placeholder}}',
position:'{{this.position}}',
textPlaceholder: {{ this.placeholder|tojson }},
position: {{ this.position|tojson }},
{% if this.geom_type == 'Point' %}
initial: false,
{% if this.search_zoom %}
Expand Down
22 changes: 22 additions & 0 deletions tests/plugins/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,25 @@ def test_search_opens_popup_bound_to_geojson_group():
)
in rendered
)


def test_search_quotes_strings():
m = folium.Map([0, 0], tiles=None)
layer = folium.GeoJson(
{
"type": "Feature",
"properties": {"state's name": "Example"},
"geometry": {"type": "Point", "coordinates": [0, 0]},
},
).add_to(m)
search = Search(
layer,
search_label="state's name",
placeholder="Search for a state's name",
).add_to(m)
rendered = normalize(search._template.module.script(search))

# tojson writes the apostrophe as \u0027, a valid JS string escape.
assert r'propertyName: "state\u0027s name",' in rendered
assert r'textPlaceholder: "Search for a state\u0027s name",' in rendered
assert 'position: "topleft",' in rendered
Loading