Skip to content
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

Pattern Overrides: Initial number of number set (or $ + 2 numbers) disappear from edited Paragraph & Heading Blocks #62347

Closed
EVERGIB opened this issue Jun 5, 2024 · 6 comments
Labels
[Feature] Block bindings [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Bug An existing feature does not function as intended

Comments

@EVERGIB
Copy link

EVERGIB commented Jun 5, 2024

Description

While using Synced Pattern Overrides on a pattern to display prices on a Paragraph Block for a restaurant menu, I noticed that the "$" and next two numbers of the price would not display on the website front end after editing from the original. Additionally, if I used only numbers for the price and no "$", I noticed that the first number of the set of numbers does not display on the front end (looks normal in the editor). The same issue happens with the "Headings" block when part of a Pattern Override.

Step-by-step reproduction instructions

  1. Create Group Block
  2. Add Heading Block and Paragraph Block to this group
  3. Create Synced Pattern from this group and Enable Overrides for the Headings and Paragraph blocks
  4. Add an instance of the synced pattern to your page
  5. edit either the heading block or paragraph block with three or more numbers, or a $ followed by three or more numbers
  6. view the page on the front-end - note that the initial number or $+2 numbers has disappeared

Screenshots, screen recording, code snippet

Images show the Pattern Override after editing the price - and the result on the website front end.
Pattern-Override_Backend-Editing
Pattern-Override_FrontEnd-Result

Environment info

Environment

  • WordPress: 6.6-beta1
  • PHP: 8.1.23
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.23)
  • Browser: Chrome 125.0.0.0 (macOS)
  • Theme: Twenty Twenty-Four 1.1
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.5

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@EVERGIB EVERGIB added the [Type] Bug An existing feature does not function as intended label Jun 5, 2024
@Mamaduka Mamaduka added the [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced label Jun 6, 2024
@Mamaduka
Copy link
Member

Mamaduka commented Jun 6, 2024

cc @talldan, @kevin940726

@talldan
Copy link
Contributor

talldan commented Jun 6, 2024

Thanks for the ping @Mamaduka, we just discovered it here too - #62220 (comment)

@SantosGuillamot
Copy link
Contributor

I believe it is caused by this refactoring of the replacement logic: link. My fault for using regex 🤦

The idea behind that pull request was to simplify the logic to support more attributes, but that didn't make it to 6.6. We should probably go back to the previous implementation and refactor the logic once the HTML API adds new methods to help with that.

@kevin940726
Copy link
Member

@SantosGuillamot Thanks for the quick PR! I tried it out myself and also found a fix while keeping the regex:

diff --git a/lib/compat/wordpress-6.5/blocks.php b/lib/compat/wordpress-6.5/blocks.php
index d3a8b3f557..a0aca9a4e5 100644
--- a/lib/compat/wordpress-6.5/blocks.php
+++ b/lib/compat/wordpress-6.5/blocks.php
@@ -85,7 +85,9 @@ function gutenberg_block_bindings_replace_html( $block_content, $block_name, str
 				return $block_content;
 			}
 			$pattern = '/(<' . $selector . '[^>]*>).*?(<\/' . $selector . '>)/i';
-			return preg_replace( $pattern, '$1' . wp_kses_post( $source_value ) . '$2', $block_content );
+			return preg_replace_callback( $pattern, function ( $matches ) use ( $source_value ) {
+				return $matches[1] . wp_kses_post( $source_value ) . $matches[2];
+			}, $block_content );
 
 		case 'attribute':
 			$amended_content = new WP_HTML_Tag_Processor( $block_content );

It seems to work. This could be an alternative solution if the regex is needed for other reasons.

@SantosGuillamot
Copy link
Contributor

Thanks for taking a look, @kevin940726! It seems safer to revert the changes and not use regex at all. The only benefits were code readability and potentially supporting more attributes, but maybe it is better to keep it the way it was until we can refactor it when the HTML API is ready. Anyway, I'd love to know more opinions.

@kevin940726
Copy link
Member

Should be closed by #62355.

pento pushed a commit to WordPress/wordpress-develop that referenced this issue Jun 13, 2024
This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content.

It also adds a unit test to cover the regression experienced in WordPress/gutenberg#62347.

Follow-up to [58298].

Props santosguillamot, gziolo.
Fixes #61385.
See #61351.




git-svn-id: https://develop.svn.wordpress.org/trunk@58398 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Jun 13, 2024
This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content.

It also adds a unit test to cover the regression experienced in WordPress/gutenberg#62347.

Follow-up to [58298].

Props santosguillamot, gziolo.
Fixes #61385.
See #61351.



Built from https://develop.svn.wordpress.org/trunk@58398


git-svn-id: http://core.svn.wordpress.org/trunk@57847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this issue Jun 13, 2024
This changeset reverts part of the changes made in [58298] to avoid using regex that can cause potential bugs. It is indeed safer to revert these changes for now and do the refactoring once the HTML API supports CSS selectors and provides a way to set inner content.

It also adds a unit test to cover the regression experienced in WordPress/gutenberg#62347.

Follow-up to [58298].

Props santosguillamot, gziolo.
Fixes #61385.
See #61351.



Built from https://develop.svn.wordpress.org/trunk@58398


git-svn-id: https://core.svn.wordpress.org/trunk@57847 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block bindings [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

5 participants