question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

text annotations with with hrefs containing encoded characters such as '#' break links

See original GitHub issue

The solution that was adopted in #2471 to enable support for encoded hrefs seems to break for characters like # and :. This seems to be because JavaScript’s encodeURI and decodeURI do not encode/decode these characters. Perhaps more nuanced used of encodeURIComponent and decodeURIComponent needs to be used?

Here’s a minimal working example in Python, which is trying to link to a Twitter query for #food lang:en, in which the # and : characters need to be encoded:

import plotly.io as pio
fig = {"data": [{"type": "bar", "x": ['<a href="http://twitter.com/search? q=%23food%20lang%3Aen">query</a>'], "y": [1]}]}
pio.show(fig)

The generated link ends up being scrambled because the hash and colon escape sequences are not decoded, but are then encoded again, resulting in the following Twitter search: %23food lang%3Aen

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Jan 21, 2022

Yes, it should work in your terminal too.

For JupyterLab (on Binder), you can run:

from IPython.display import display, Javascript

display(Javascript("""
window._encodeURI = window._encodeURI || encodeURI;
encodeURI = uri => _encodeURI(uri)
    .replace('%2523', '%23')  // #
    .replace('%253A', '%3A')  // :
    .replace('%252b', '%2b'); // +
"""))
0reactions
vpicouetcommented, Jan 21, 2022

Thanks a lot for your help!!! It works perfectly !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross Site Scripting Prevention - OWASP Cheat Sheet Series
Here are some examples of encoded values for specific characters. ... <a href="http://www.owasp.org?test=$varUnsafe">link</a >. Encode all characters with ...
Read more >
Links in HTML documents - W3C
The following HTML excerpt contains two links, one whose destination anchor is an ... Since links may point to documents encoded with different...
Read more >
How to use ampersands in HTML: to encode or not to encode?
An explanation of when to use encoded ampersands (&) in HTML and Javascript and when not to encode them.
Read more >
[CONFSERVER-52420] Links containing certain encoded special ...
This ticket stems from CONFSERVER-45966 . In that ticket, if you enter a link that contains url-encoded characters such as %25 or %2f,...
Read more >
Google fonts URL break HTML5 Validation on w3.org
URL encode the | (pipe characters) in the href attribute ( %7C ): <link rel="stylesheet" type="text/css" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found