New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autop: Use placeholders to protect script, style tags #15129
Conversation
@azaozz indirectly left some feedback on this approach from my related comments on the PHP-equivalent Trac ticket: https://core.trac.wordpress.org/ticket/2833#comment:37 From that, I'm wondering if the specific change to include https://github.com/WordPress/gutenberg/pull/15129/files#diff-eb22f4279633ce3065fcbb5f18189916L169 |
Yes, thinking it would be better to not add it to allBlocks. "Unwrapping" them would be good, but only when the The problem is the <p><script>alert(1);</script>This is some text...</p>
<p>This is some more text...<script>alert(2);</script></p> There may be other edge cases like: <p><script>alert(1);</script>
This is some text...</p> where the line break may turn into a redundant As autop hopefully is "on its way out", thinking it will be sufficient to unwrap // If a script or style tag is wrapped in <p>, unwrap it.
text = text.replace( /<p>(<(script|style)[/s/S]+?<\/\\2>)<\/p>/g, '$1' ); |
On second thought, can we just drop autop from Gutenberg completely? :) The PHP The edge case of having only one classic block can be solved perhaps by adding an "empty" block at the beginning? Something like |
Up again here :) Should we land this? |
Looking again, the only potential problem I see is adding of the More context: "historically" the js version of Perhaps having |
Still unwrap tags with same treatment as block tags
256fab7
to
3a0aebf
Compare
Thanks for the bump, and apologies I missed your original comment from October @youknowriad . It must have been a casualty of my extended leave. Thanks also @azaozz for the feedback. It's been a while since I looked at this, so I needed a refresher. Based on the prior conversation, it seemed to me that the original approach here in trying to consider The additional changes in 3a0aebf should address this:
Added this as well in dc39e37, using as a test case the example from Trac#9437. |
Thinking on this some more, I'm starting to wonder how much this would really help, at least without a corresponding change in the PHP implementation (Trac#2833). This code is relevant for only the classic block. Even if the output in the browser is "correct", the server will still likely reintroduce the same problems when it applies Maybe I'm missing something. Is there anything specific about Gutenberg and the issues being described in #9056 which weren't already present in the 14 years since Trac#2833 was opened? |
Note about the status here: The changes here should effectively be considered complete. However, as noted in #15129 (comment), this is only one part of the bigger issue with how |
@azaozz Do you think bringing those changes to PHP is something you could help with? or who would be the right person to help here? I admit I don't trust myself to make this kind of changes in WP :) |
Sure. Have looked at both the JS and PHP autop many times over the years, and the changes in this PR make sense. IMHO this is a good place to do some "tests first" coding. Will need to find all edge cases and write tests for them before changing the actual code. Looking at the current patches (both JS and PHP) they'll need quite a bit more testing before deemed "ready". As far as I see there are three parts to this:
|
@mcsf @youknowriad @azaozz were folks still working on this one? What do y'all suggest for next steps? This one is pretty tricky so I think we'd at least need reviews from folks who are familiar with autop. This came up in core-editor triage |
No work happening from my side or Riad's. I don't know about @azaozz. Indeed, it's tricky, and Andrew raised good questions about the pertinence of the change in #15129 (comment). If we do want to go forward, it's a delicate task that someone would need to own. |
Fixes #9056
Related: https://core.trac.wordpress.org/ticket/2833#comment:19
This pull request seeks to resolve an issue with the
autop
implementation wherebr
andp
elements are added within the contents of ascript
orstyle
tag. It also avoids adding a wrappingp
toscript
tags (already present forstyle
).The underlying issue is described at #9056 (comment) . While one possible solution would have been to fix the incorrectly-ported regular expression backreference, it would have left the remaining issue of paragraphs being added within the elements. For that reason, and inspired by prior art by @cmmarslender at Trac#2833, the solution here extends the approach used for
pre
tag placeholder substitution to apply tostyle
andscript
tags as well.Testing Instructions:
Repeat steps to reproduce from #9056, verifying that neither
br
norp
tags are inserted within the contents of a post consisting only of this content (i.e. no blocks content, equivalent to a pre-WordPress 5.0 post).Ensure unit tests pass: