-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix usage of preg_quote()
#10998
Fix usage of preg_quote()
#10998
Conversation
The end tag pattern is currently generated like this: ``` $end_tag_pattern = '/<!--\s+\/wp:' . str_replace( '/', '\/', preg_quote( $block_name ) ) . '\s+-->/'; ``` Instead of separately using a string replace to replace `/` with `\/`, it is preferable to use the second argument `$delimiter` that the `preg_quote()` function provides. See http://php.net/manual/en/function.preg-quote.php
Note also that the behavior of From the PHP docs at http://php.net/manual/en/function.preg-quote.php : |
@@ -232,7 +232,7 @@ function do_blocks( $content ) { | |||
$inner_content = ''; | |||
|
|||
if ( ! $is_self_closing ) { | |||
$end_tag_pattern = '/<!--\s+\/wp:' . str_replace( '/', '\/', preg_quote( $block_name ) ) . '\s+-->/'; | |||
$end_tag_pattern = '/<!--\s+\/wp:' . preg_quote( $block_name, '/' ) . '\s+-->/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a great change. but…while we're at it, what if we changed the delimiter too so remove a tiny bit of escaping?
'~<!--\s+/wp:' . preg_quote( $block_name, '~' ) . '\s+-->~'
just a thought, but it only saves one escape 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good change to me from the code perspective!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second argument seems to have been designed for this, so makes total sense 👍
#10998 (comment) also seems reasonable, though not strictly related to what's being proposed for improvement here. Worth a separate issue / ticket?
The end tag pattern is currently generated like this: ``` $end_tag_pattern = '/<!--\s+\/wp:' . str_replace( '/', '\/', preg_quote( $block_name ) ) . '\s+-->/'; ``` Instead of separately using a string replace to replace `/` with `\/`, it is preferable to use the second argument `$delimiter` that the `preg_quote()` function provides. See http://php.net/manual/en/function.preg-quote.php
…rnmobile/merge-blocks-on-backspace * 'master' of https://github.com/WordPress/gutenberg: Do not add isDirty prop to DOM (#11093) Format API (#10209) Remove 4.2 deprecated features (#10952) Update `@wordpress/hooks` README to include namespace mention (#11061) Feature: save lock control via actions (#10649) Fix usage of `preg_quote()` (#10998) Update plugin version to 4.1.1 (#11078) Improve preloading request code (#11007) Fix dynamic blocks not rendering in the frontend (#11050) Media & Text: Fixing vertical alignment of the image (#11025) Date: Mark getSettings as experimental (#10636) Improve handling of centered 1-col galleries with small images (#11040) Use better help text for ALT text input; fixes #8391. (#11052) # Conflicts: # packages/editor/src/components/rich-text/index.native.js
The end tag pattern is currently generated like this:
Instead of separately using a string replace to replace
/
with\/
, it is preferable to use the second argument$delimiter
that thepreg_quote()
function provides.See http://php.net/manual/en/function.preg-quote.php