[BUGFIX] Resolve double-backslash escape in code text roles#1189
Closed
CybotTM wants to merge 1 commit intoTYPO3-Documentation:mainfrom
Closed
[BUGFIX] Resolve double-backslash escape in code text roles#1189CybotTM wants to merge 1 commit intoTYPO3-Documentation:mainfrom
CybotTM wants to merge 1 commit intoTYPO3-Documentation:mainfrom
Conversation
All 20 code-type text roles pass $rawContent to CodeInlineNode,
which preserves RST escape sequences literally. This means \\
stays as \\ instead of resolving to \ as the author intended.
Add str_replace('\\\\', '\\') in the CodeInlineNode constructor
to resolve double-backslash sequences. This is safe for PHP
namespace paths (\TYPO3\CMS\Core) which use single backslashes
and are not affected by this replacement.
Resolves: TYPO3-Documentation#1188
Signed-off-by: Sebastian Mendel <info@sebastianmendel.de>
Member
|
Did you note there was a change in the guide on friday? Not sure we would still need this change? |
Contributor
Author
|
yes I know, was initiated by phpDocumentor/guides#1308 |
Contributor
Author
|
so, yes, should make this "demonstration" obsolete. |
Member
|
@CybotTM would you like to close this pr then? Or maybe just keep the tests? |
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.
Summary
Demonstrates a possible fix for #1188 —
:rst:(and all other code-type text roles) display\\literally instead of resolving to\.All 20 code-type text roles pass
$rawContenttoCodeInlineNode, which preserves RST escape sequences literally. This means\\in the RST source stays as\\in the rendered output instead of resolving to\as the author intended.Approach: Add
str_replace('\\\\', '\\', $value)in theCodeInlineNodeconstructor to resolve double-backslash escape sequences.Changes
CodeInlineNode.php— one line added in constructorcode-textrole-escapecovering:rst:,:shell:,:typoscript:,:yaml:with\\and plain contentInline-code-and-textroles/Index.rstScope
This PR addresses Test B from the issue (double backslash). Tests A, D, E involve the upstream
InlineLexerin phpDocumentor/guides consuming\`asESCAPED_SIGNbefore text role boundaries are resolved — that requires a separate upstream fix.The
str_replaceapproach is blind — it cannot distinguish between:\\meaning "RST escaped backslash → display\" (the bug we're fixing)\\meaning "literal double backslash in code that should stay as\\"PHP code samples that would break:
:php:'/\d+/'``'/\\d+/''/\d+/':php:"hello\nworld"``"hello\\nworld""hello\nworld":php:preg_match('/\\/')``preg_match('/\\\\/')preg_match('/\\/')This is the fundamental tension identified in the issue:
$rawContentwas introduced by phpDocumentor/guides#533 to preserve literal backslashes for PHP namespaces (\TYPO3\CMS\Core), but that same literalness prevents\\from resolving to\.A proper fix needs to happen upstream in the parser/lexer layer where
ESCAPED_SIGNtokens are available — only the parser knows which\\came from an intentional RST escape vs which\was just a literal backslash character in code.Test plan
make test-integration ENV=local— all 113 tests passmake code-style ENV=local— 0 issuesmake phpstan ENV=local— no errorsmake rendertest ENV=local— inspect "Escape handling in code text roles" section:php:namespace paths still render correctly (existingcode-phptest)