Shortcode: Fix parsing when attribute values contain brackets#76924
Shortcode: Fix parsing when attribute values contain brackets#76924
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @joelyoder, @justinsc. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| await expect( | ||
| editor.canvas.getByRole( 'document', { | ||
| name: 'Block: Custom HTML', | ||
| } ) | ||
| ).toBeHidden(); |
There was a problem hiding this comment.
Conversion on trunk creates an HTML block, instead of a shortcode.
|
Size Change: +35 B (0%) Total Size: 7.73 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in e96baa6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23793561097
|
Can we explain more what the divergence is and why “correctly” here involves such a divergence? If there is a problem with the PHP side, it also needs updating. In fact, if our test suites diverge it would be good to ensure the same tests exist on both sides. |
| * Differences from the PHP regex: | ||
| * | ||
| * - The closing shortcode tag is captured as group 6 (used by `fromMatch`). | ||
| * - Quoted attribute values may contain `]` (e.g. `text="[Click here]"`). |
There was a problem hiding this comment.
@dmsnell, I've added this note regarding differences. The main one is that the quoted attributes can contain brackets. Capturing groups is mostly the same.
There was a problem hiding this comment.
thanks @Mamaduka — I was speaking more of behavioral differences rather than syntax though. we know that the PCRE engine in PHP is different in slight ways from the JS engine; is this change about matching the behaviors of the PHP shortcode handling or is this diverging from how the server understands shortcodes?
What?
Closes #8937.
PR fixes a bug with the shortcode parser when values contain brackets. I've also updated
RegExpto be more readable, similar toget_shortcode_regex().This change diverges the regex from the PHP equivalent a bit, but is required to correctly convert shortcodes.
Why?
Previously, the regex would split the shortcode at the first
]inside a quoted value, causing incorrect block conversionTesting Instructions
[my_shortcode param="foo" link_text="[Click here]" bar="baz"].This is now covered by e2e tests.
Testing Instructions for Keyboard
Same.
Use of AI Tools
Used Claude to update
RegExp, it's better at it than me. Reviewed and tested changes manually.