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.

[BUG] Markup escaping not working as expected

See original GitHub issue

Describe the bug It’s a bit of an edge case, but right now it’s not possible to output a backslash immediately before a square bracket starting a markup token. While it does properly output a single backslash if you feed in r'\\' followed by a markup token, it still disables interpreting the token as markup.

To Reproduce Working cases:

rich.print(r'[bold]text[/]') prints “textrich.print(r'\[not a tag]') prints “[not a tag]”

Not working case: rich.print(r'\\[bold]some text[/]') gives an error about an unexpected close tag, because it doesn’t treat “[bold]” as markup. The expected result here was “\text”, a single backslash followed by the text in bold.

Adding more backslashes also produces a surprising result. It seems like the rightmost backslash is always consumed to disable markup on the square bracket, but all the previous backslashes are passed through as-is, rather than having every other backslash escape the following one. So, with three backslashes, I was expecting one to be output (consuming the first two of the input) and one to be left over to escape the square bracket and disable markup. WIth four backslashes, I was expecting two backslashes to be output (consuming all four of the input) and the square bracket after that to be treated as markup.

Platform Rich 9.5.1 on macOS Mojave (10.14.6) with Apple’s Terminal.app.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
ronfcommented, Jan 7, 2021

Looks good - thanks!

Preserving backslashes as-is elsewhere in the string makes sense to me. I do something similar in some code I wrote which allows users to input raw unicode characters by entering something like \u203c or \U0001f348 inside their input string, converting those sequences to a single Unicode character when the entered code point is a valid printable character. Entering \\u203c is turned into \u203c (removing one backslash), but entering \\ not followed by a “u” or “U” and the right number of hex digits is left alone.

0reactions
ronfcommented, Jan 8, 2021

Upgraded here - looks great. Thanks so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Markup escaping not working as expected · Issue #878 ...
Describe the bug It's a bit of an edge case, but right now it's not possible to output a backslash immediately before a...
Read more >
Using \[ in Markup macro does not escape as expected - Jira
When using a \ backslash to escape a [ square bracket, the Markup has an incoherent behaviour. How to reproduce. Create a new...
Read more >
escape character not working as expected - Stack Overflow
I am not sure how to escape a string parameter and I have come across this problem so many times, Please help if...
Read more >
Badly escaped HTML results in plain text instead of markup in ...
There's an HTML escape bug that's reproducible network-wide. Also mentioned on Super User, this is not just "ugly", but also causes prevents the ......
Read more >
0006204: no proper escaping of html code in texts - MantisBT
View Issue Details ; if descriptions (and probably other text) contain html markup (such as the text "<p>", which due to this bug...
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