Skip to content

Escape backslashes and backticks in Tooltip text - #2320

Merged
hansthen merged 1 commit into
python-visualization:mainfrom
nk-batman21:fix/tooltip-backslash-escape
Oct 26, 2026
Merged

hansthen merged 1 commit into
python-visualization:mainfrom
nk-batman21:fix/tooltip-backslash-escape

Conversation

@nk-batman21

Copy link
Copy Markdown
Contributor

Tooltip puts 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 example folium.Marker([0, 0], tooltip=r"C:\data\2019") fails in the browser with "SyntaxError: Octal escape sequences are not allowed in template strings", and tooltip="use `folium`" fails with "missing ) after argument list". This hits any layer that takes tooltip= (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 same escape_backticks call 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 and mypy folium.
Checked: syntax-checked the rendered map script with node for Marker, CircleMarker, PolyLine, GeoJson and a Tooltip object, and evaluated the generated bindTooltip call for Windows paths, backticks, HTML with quotes and an empty string; the text comes back unchanged.

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.
@hansthen

Copy link
Copy Markdown
Collaborator

Running the tests, but looks good to me.

@hansthen

Copy link
Copy Markdown
Collaborator

@nk-batman21 Merged! Thank you.

@hansthen
hansthen merged commit 6314675 into python-visualization:main Oct 26, 2026
16 checks passed

This branch was successfully deployed

1 active deployment
pypi — 9fbebdf5 Deployed Oct 26, 2026 by nk-batman21 via packages #2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backslashes in popup break page.

2 participants