Repository navigation
Conversation
This branch has not been deployed
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 #1114.
makeMarkdown.txtcallsunescapeHTMLEntitiesonnode.nodeValue. The DOM has already decoded entities there, so this decodes them a second time. Text the page shows as<comes out as<. Text shown as<br>comes out as a real<br>tag.The fix drops the second decode. It escapes
&only when it starts something that looks like an entity (&name;,<,<). It escapes<only when a letter or/follows. Plaina & b,AT&T,1 < 2andx <3stay as they are, so the existingescaping-html-entitiesfixture still passes.The issue suggested backslash escapes (
\<and\<br>). Those also render right in current showdown. I used&and<because the docs put\<tag>escaping under the opt-inbackslashEscapesHTMLTagsoption, and the entity form works in any Markdown parser. Happy to switch to the backslash form if you prefer it.Behavior changes (makeMarkdown output only)
<,&,",©,<or<now comes out as&lt;and so on. Before, it was decoded to the character, or left as an entity that makeHtml then decoded.<followed by a letter or/now comes out as<. This also hits harmless text such asa<b, which used to staya<b. Both render the same.<https://e.x/>,<a@b.co>) no longer turns into a link on the way back.Not covered
<!or<?(for example a literal<!-- x -->) still passes through as is. Escaping it would change the existinghtml-commentsfixture, so I left it out.<or&is still lost, because txt.js does not escape backslashes. That was already wrong before this change and is a separate gap.Tests
test/functional/makemarkdown/cases/standard/escaping-entity-like-text.{html,md}. It fails on develop and passes with the fix, in both the jsdom and node projects.npx vitest runlocally (Windows, Node 24): 25 files, 3176 tests passed.npx eslint .: 0 errors. The one warning is an existing one insrc/subParsers/makehtml/decodeEntities.js.makeHtml(makeMarkdown(html))must show the same text and the same tags ashtml. On 20,000 random strings of entity-like and tag-like text insidep,h2,li,em,a,blockquoteand table cells, 8,308 failed before and 12 failed after. All 12 are the<!case above. Nothing that passed before fails now.Validated with Claude Opus 5.5.