diff --git a/folium/utilities.py b/folium/utilities.py index 48cabb715d..6a12e4bfbf 100644 --- a/folium/utilities.py +++ b/folium/utilities.py @@ -4,7 +4,6 @@ import json import math import os -import re import tempfile import uuid from collections.abc import Iterable, Iterator, Sequence @@ -412,8 +411,8 @@ def remove_empty(**kwargs: TypeJsonValue) -> dict[str, TypeJsonValueNoNone]: def escape_backticks(text: str) -> str: - """Escape backticks so text can be used in a JS template.""" - return re.sub(r"(? str: diff --git a/tests/test_map.py b/tests/test_map.py index 581e603ff7..551ffb2b3d 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -234,15 +234,17 @@ def test_popup_backticks(): assert normalize(rendered) == normalize(expected) -def test_popup_backticks_already_escaped(): +def test_popup_backslashes(): m = Map() - popup = Popup("back\\`tick").add_to(m) + # A backslash followed by a digit would become an illegal octal escape + # sequence inside the JS template literal if it is not escaped, see #1907. + popup = Popup("C:\\path\\20190221").add_to(m) rendered = popup._template.render(this=popup, kwargs={}) - expected = """ + expected = r""" var {popup_name} = L.popup({{ "maxWidth": "100%", }}); - var {html_name} = $(`