fix: stop double escaping in code blocks - #307
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
Block content is escaped once on save, so render_block() must decode it once before passing it to the shortcode callback. The language check added in 3.7.2 skipped the decode for plain text blocks, leaving entities that got escaped a second time on output. Also accept a bare <pre> tag when extracting the code, since the block saves one without attributes. Fixes Automattic#286
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 #286
Changes proposed in this Pull Request
render_block(), always runhtmlspecialchars_decode()on the extracted code. Since 3.7.2 (PR Fix escaping when language is unknown #283) the decode was behind a language check, so Plain Text blocks (empty language) stayed escaped and got escaped a second time in the shortcode callback. A block with<foo>/bar &showed<foo>/bar &on the front end.<pre>tag when extracting the code. The block saves<pre>with no attributes, and the old pattern#<pre [^>]+>([^<]+)?</pre>#required an attribute and also stopped at any<inside the code.shortcode_callback(). Block content is always raw at this point, but a post stored as encoded (code format 2) would make the callback strip tags instead of escaping once.Testing instructions
<foo>andbar &.<foo>andbar &literally, not<foo>/bar &.[sourcecode]shortcodes. Output should be unchanged.