Repository navigation
Escape backslashes and backticks in Tooltip text - #2320
Merged
hansthen merged 1 commit intoOct 26, 2026
Merged
Conversation
Tooltip text is rendered inside a JS template literal, like Popup text. A backslash or backtick in it made the page script invalid and the map did not render. Use escape_backticks for Tooltip as python-visualization#2240 did for Popup.
Collaborator
|
Running the tests, but looks good to me. |
Collaborator
|
@nk-batman21 Merged! Thank you. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tooltipputs its text into a JavaScript template literal without escaping it, so a backslash or a backtick in a tooltip makes the page script invalid and the whole map renders blank. For examplefolium.Marker([0, 0], tooltip=r"C:\data\2019")fails in the browser with "SyntaxError: Octal escape sequences are not allowed in template strings", andtooltip="use `folium`"fails with "missing ) after argument list". This hits any layer that takestooltip=(Marker, CircleMarker, PolyLine, GeoJson, ...), e.g. when tooltips show Windows file paths.The same text already works in
popup=since #2240, which fixed #1907. In #1907 it was suggested to make Tooltip behave the same way, and this change does that: Tooltip text now goes through the sameescape_backtickscall as Popup text. As with Popup, text that was escaped by hand will now show the extra backslashes.Ran:
pytest tests/test_map.py(the new test fails without the change), the rest of the non-selenium test suite (no new failures), ruff, black andmypy folium.Checked: syntax-checked the rendered map script with node for Marker, CircleMarker, PolyLine, GeoJson and a
Tooltipobject, and evaluated the generatedbindTooltipcall for Windows paths, backticks, HTML with quotes and an empty string; the text comes back unchanged.