fix: unescape all ASCII punctuation in escapeReplacer - #565
Open
koriyoshi2041 wants to merge 1 commit into
Open
Conversation
glamour strips backslash escapes itself rather than going through goldmark's HTML writer, but escapeReplacer followed the markdownguide.org list and was missing several CommonMark-escapable characters. Most visibly a backslash before ~ was left as-is (issue charmbracelet#503), which matters because ~ is strikethrough; the double-quote, dollar, percent, ampersand, apostrophe, comma, slash, colon, semicolon, equals, question mark, at, and caret escapes were affected too. List every ASCII punctuation character so a backslash before any of them is stripped, per the CommonMark spec.
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 #503.
glamour does its own backslash-unescaping in
escapeReplacer(ansi/baseelement.go) instead of going through goldmark's HTML writer. That replacer was built from the markdownguide.org list and is missing several characters that CommonMark allows to be escaped, so the backslash is left in the rendered output for:\~is the one reported in #503 and is the most visible, since~is used for strikethrough —\~foo\~rendered as\~foo\~instead of~foo~.Per the CommonMark spec, a backslash before any ASCII punctuation character is an escape, so
escapeReplacernow lists all of them.Added
TestEscapeReplacerinansi/renderer_test.gocovering the previously-missing characters plus a couple that already worked, to guard against regressions.go test ./ansi/...passes and the existing golden tests are unchanged.