Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special char encoding in notebook #76

Merged

Conversation

Conengmo
Copy link
Member

@Conengmo Conengmo commented May 8, 2020

Close python-visualization/folium#1320

When we base64 decode the iframe for in notebooks we use JS atob. This function doesn't handle characters with multiple code units as expected. Mitigate this by not using base64 encoding, but percent-encoding. On the JS side we can decode this with decodeURIComponent without issues.

Example:

>>> title = '5/7 %, Линейная улица, é "Berdsk"'
>>> title.encode('utf-8')
b'5/7 %, \xd0\x9b\xd0\xb8\xd0\xbd\xd0\xb5\xd0\xb9\xd0\xbd\xd0\xb0\xd1\x8f \xd1\x83\xd0\xbb\xd0\xb8\xd1\x86\xd0\xb0, \xc3\xa9 "Berdsk"'
>>> urllib.parse.quote(title)
'5/7%20%25%2C%20%D0%9B%D0%B8%D0%BD%D0%B5%D0%B9%D0%BD%D0%B0%D1%8F%20%D1%83%D0%BB%D0%B8%D1%86%D0%B0%2C%20%C3%A9%20%22Berdsk%22'

--- To do ---

  • Add a test case

@Conengmo
Copy link
Member Author

I added a test and it passes, so I think this one is ready to go.

@Conengmo Conengmo merged commit 5887b9b into python-visualization:master Jun 18, 2020
@Conengmo Conengmo deleted the fix-notebook-special-chars branch June 18, 2020 06:35
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.

Unicode issue in tooltips on Jupyter notebook
1 participant