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
2 changes: 1 addition & 1 deletion folium/plugins/float_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FloatImage(MacroElement):

{% macro html(this,kwargs) %}
<img id="{{this.get_name()}}" alt="float_image"
src="{{ this.image }}"
src="{{ this.image|e }}"
style="z-index: 999999">
</img>
{% endmacro %}
Expand Down
2 changes: 1 addition & 1 deletion folium/plugins/timestamped_geo_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TimestampedGeoJson(JSCSSMixin, MacroElement):
_getDisplayDateFormat: function(date){
var newdate = new moment(date);
console.log(newdate)
return newdate.format("{{this.date_options}}");
return newdate.format({{ this.date_options|tojson }});
}
});
{{this._parent.get_name()}}.timeDimension = L.timeDimension(
Expand Down
2 changes: 1 addition & 1 deletion folium/plugins/vectorgrid_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class VectorGridProtobuf(JSCSSMixin, Layer):
_template = Template("""
{% macro script(this, kwargs) -%}
var {{ this.get_name() }} = L.vectorGrid.protobuf(
'{{ this.url }}',
{{ this.url|tojson }},
{%- if this.options is defined %}
{{ this.options if this.options is string else this.options|tojavascript }}
{%- endif %}
Expand Down
9 changes: 9 additions & 0 deletions tests/plugins/test_float_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ def test_float_image():

bounds = m.get_bounds()
assert bounds == [[None, None], [None, None]], bounds


def test_float_image_escapes_src():
m = folium.Map()
image = 'https://example.com/a.png?x=1&y="2"'
plugins.FloatImage(image).add_to(m)
out = m.get_root().render()
assert 'src="https://example.com/a.png?x=1&amp;y=&#34;2&#34;"' in out
assert 'y="2"' not in out
10 changes: 9 additions & 1 deletion tests/plugins/test_timestamped_geo_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_timestamped_geo_json():
_getDisplayDateFormat: function(date){
var newdate = new moment(date);
console.log(newdate)
return newdate.format("{{this.date_options}}");
return newdate.format({{ this.date_options|tojson }});
}
});
{{this._parent.get_name()}}.timeDimension = L.timeDimension(
Expand Down Expand Up @@ -208,3 +208,11 @@ def test_timestamped_geo_json():

bounds = m.get_bounds()
assert bounds == [[-53.0, -158.0], [50.0, 158.0]], bounds


def test_timestamped_geo_json_date_options_with_quotes():
m = folium.Map()
data = {"type": "FeatureCollection", "features": []}
plugins.TimestampedGeoJson(data, date_options='YYYY "Q"Q').add_to(m)
out = m.get_root().render()
assert 'newdate.format("YYYY \\"Q\\"Q");' in out
8 changes: 8 additions & 0 deletions tests/plugins/test_vectorgrid_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ def test_vectorgrid_dict_options():
continue

assert f'"{k}": {v}' in out


def test_vectorgrid_url_with_quote():
m = folium.Map()
url = "https://example.com/{z}/{x}/{y}.pbf?name=O'Neil"
VectorGridProtobuf(url, "test").add_to(m)
out = m.get_root().render()
assert r'"https://example.com/{z}/{x}/{y}.pbf?name=O\u0027Neil"' in out
Loading