diff --git a/folium/plugins/float_image.py b/folium/plugins/float_image.py index 5cf8c1f7a4..30b45c112c 100644 --- a/folium/plugins/float_image.py +++ b/folium/plugins/float_image.py @@ -37,7 +37,7 @@ class FloatImage(MacroElement): {% macro html(this,kwargs) %} float_image {% endmacro %} diff --git a/folium/plugins/timestamped_geo_json.py b/folium/plugins/timestamped_geo_json.py index 11023bfca1..84a72aa695 100644 --- a/folium/plugins/timestamped_geo_json.py +++ b/folium/plugins/timestamped_geo_json.py @@ -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( diff --git a/folium/plugins/vectorgrid_protobuf.py b/folium/plugins/vectorgrid_protobuf.py index 3438541a38..3ed8c10560 100644 --- a/folium/plugins/vectorgrid_protobuf.py +++ b/folium/plugins/vectorgrid_protobuf.py @@ -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 %} diff --git a/tests/plugins/test_float_image.py b/tests/plugins/test_float_image.py index 365e8ae68a..289857c08c 100644 --- a/tests/plugins/test_float_image.py +++ b/tests/plugins/test_float_image.py @@ -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&y="2""' in out + assert 'y="2"' not in out diff --git a/tests/plugins/test_timestamped_geo_json.py b/tests/plugins/test_timestamped_geo_json.py index dbe4199be0..23cd4a1a03 100644 --- a/tests/plugins/test_timestamped_geo_json.py +++ b/tests/plugins/test_timestamped_geo_json.py @@ -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( @@ -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 diff --git a/tests/plugins/test_vectorgrid_protobuf.py b/tests/plugins/test_vectorgrid_protobuf.py index 99b5ddc247..117e3f5728 100644 --- a/tests/plugins/test_vectorgrid_protobuf.py +++ b/tests/plugins/test_vectorgrid_protobuf.py @@ -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