Skip to content

fix: escape backslashes in popup text (fixes #1907)#2240

Open
cycsmail wants to merge 1 commit into
python-visualization:mainfrom
cycsmail:fix/popup-backslash-escape
Open

fix: escape backslashes in popup text (fixes #1907)#2240
cycsmail wants to merge 1 commit into
python-visualization:mainfrom
cycsmail:fix/popup-backslash-escape

Conversation

@cycsmail

Copy link
Copy Markdown

Fixes #1907

Problem

Popup HTML goes into a JavaScript template literal (backtick string). If the text has a backslash followed by a digit (e.g. a Windows path like C:\path\20190221), the JS engine reads it as an octal escape sequence, which is illegal in template literals/strict mode. The map fails to load with Uncaught SyntaxError: octal escape sequences can't be used in untagged template literals.

escape_backticks() only escaped backticks, so any backslash in the text leaked straight through.

Fix

Escape backslashes as well as backticks before the text goes into the template literal (backslashes first, so the escape we add for backticks isn't itself mangled):

return text.replace("\\", "\\\\").replace("`", "\\`")

Covers both call sites that embed text in backtick literals, Popup and ClickForMarker. The previous negative-lookbehind regex assumed callers pre-escaped backticks, which they don't, so I dropped it (and the now-unused import re).

Test plan

  • Added tests/test_map.py::test_popup_backslashes, which renders a popup with backslash+digit sequences and asserts the backslashes are doubled in the output. It fails on the unpatched tree (confirmed by stashing the fix) and passes with it.
  • The existing test_popup_backticks still passes.
  • ruff and black --check clean on the changed files.

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.

1 participant