Repository navigation
Fix < in code blocks being escaped twice in safe mode - #738
Open
LuisFigueroaG wants to merge 3 commits into
Open
LuisFigueroaG wants to merge 3 commits into
LuisFigueroaG wants to merge 3 commits into
Conversation
In safe mode, incomplete tags like the `<3` in `i<3` are swapped for a literal `<` before the block gamut runs. Code blocks then encode the `&` again, so `i<3` inside an indented or fenced code block came out as `i&lt;3`. Hash the `<` instead, the same way complete tags are hashed, so code blocks leave it alone. The hash is also added to the code table so header ids and TOC entries keep using the plain text. Fixes trentm#240
…e-block-escaping # Conflicts: # CHANGES.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #240
In safe mode, a
<that looks like the start of a tag (a<b,i<3) is replaced with<early on, before the block gamut runs. When that text is inside a code block, the code block encoding escapes the&again, so the example from the issue renders as:The blockquote from the original report isn't swallowed any more, but the double escaping is still there with the same input. It also happens in fenced code blocks (without pygments), in code blocks nested in lists, and in
Markdown Documentation - Syntax.textwhen converted in safe mode.What I changed: the escaped
<is now hashed, the same way complete tags are already hashed in safe mode, so code blocks leave it alone and it's restored as<at the end. Header ids unescape it before slugifying, so# Comparing a<bkeeps its current id.Tests:
tm-cases/safe_mode_incomplete_tags_in_code_blockscovers indented, fenced and list-nested code blocks, a heading witha<b, and a literal<in a code block (which should still come out as&lt;). It fails on master.test.py -- -knownfailure: OKtest/test_redos.py: 10 tests, OKpycodestyle lib/markdown2.py: same warning count as masterI also ran every
.textfile undertest/through master and this branch, with no safe mode,escapeandreplace, and with and without a large set of extras. The only difference outside email obfuscation (random on every run) was the intended one in the Syntax document.