Skip to content

fix: allow dollar sign in custom blocks#946

Merged
nicholasio merged 4 commits intodevelopfrom
fix/allow-dollar-sign-custom-blocks
Apr 1, 2026
Merged

fix: allow dollar sign in custom blocks#946
nicholasio merged 4 commits intodevelopfrom
fix/allow-dollar-sign-custom-blocks

Conversation

@pdavies88
Copy link
Copy Markdown
Contributor

@pdavies88 pdavies88 commented Mar 27, 2026

Description of the Change

Client would like to be able to use dollar signs as text within custom blocks. Currently because of preg_replace() dollar signs and the immediate following text are being stripped and convert to empty strings.

How to test the Change

Create a custom block that allows a user to provide string output via a text input or text area. Use a dollar sign in those fields and it should output example: $50

Changelog Entry

Changed - Existing functionality

Credits

Props @pdavies88

Checklist:


Note

Low Risk
Low risk: small, targeted escaping change to a preg_replace replacement string, covered by new regression tests.

Overview
Fixes a Gutenberg rendering edge case where $... sequences inside serialized JSON block attributes were being treated as preg_replace() replacement tokens and removed during data-wp-block injection.

set_block_attributes_tag_api() now escapes backslashes and dollar signs in the replacement string, and tests add coverage for dollar-sign values (including a new block roundtrip case) plus a changeset entry.

Written by Cursor Bugbot for commit 0dc499b. This will update automatically on new commits. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
headstartwp-app-router Ready Ready Preview, Comment Mar 31, 2026 3:40pm
headstarwp Ready Ready Preview, Comment Mar 31, 2026 3:40pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 27, 2026

🦋 Changeset detected

Latest commit: 1d9e7f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@headstartwp/headstartwp Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pdavies88
Copy link
Copy Markdown
Contributor Author

@nicholasio I chatted with @jacobdubail about this today and I think this is the easiest path forward for my situation. On Digital Democracy the client wants to be able to write out $50 million into a Bill Card custom block. They are the yellow cards right under K12 and Higher Education Bills: https://calmatters.digitaldemocracy.org/issues/education. Because we have these set up as custom blocks with TextareaControl when the data gets processed via the Gutenberg.php file the dollar sign is getting stripped out an converted to an empty space. The hope here is that we can allow dollar signs in this specific use case so that it functions like a core block and doesn't strip that character.

I also created this PR wasn't sure which directory is correct for this update: 10up/headstartwp-plugin#1

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/wp-nextjs-app

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 83.62 KB (🟢 -42.45 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/headstartwp

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/headstartwp

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/wp-nextjs-app

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 83.62 KB (🟢 -42.45 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Copy link
Copy Markdown
Member

@nicholasio nicholasio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

Could you add a couple of tests to cover this edge case as well as add a changeset?

@pdavies88
Copy link
Copy Markdown
Contributor Author

@nicholasio just added the tests and a .md in the changesets folder. Please let me know if any other updates are needed or if there are different places that I need to update as well.

@pdavies88 pdavies88 requested a review from nicholasio March 31, 2026 05:46
@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/headstartwp

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Test asserts attribute that method never adds
    • Removed the incorrect assertion checking for data-wp-block-name attribute, which is not added by set_block_attributes_tag_api(), allowing the actual dollar-sign preservation test to execute.

Create PR

Or push these changes by commenting:

@cursor push 0c1158d2b9
Preview (0c1158d2b9)
diff --git a/wp/headless-wp/tests/php/tests/TestGutenbergIntegration.php b/wp/headless-wp/tests/php/tests/TestGutenbergIntegration.php
--- a/wp/headless-wp/tests/php/tests/TestGutenbergIntegration.php
+++ b/wp/headless-wp/tests/php/tests/TestGutenbergIntegration.php
@@ -173,7 +173,6 @@
 
 		$enhanced = $this->parser->set_block_attributes_tag_api( $placeholder, $html, $attrs_json );
 
-		$this->assertStringContainsString( 'data-wp-block-name="', $enhanced, 'Sanity check: block-name attribute should exist.' );
 		// The core assertion: `$50` should not be interpreted by preg_replace() replacement parsing.
 		$this->assertStringContainsString( '$50 million', $enhanced );
 	}

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.


$enhanced = $this->parser->set_block_attributes_tag_api( $placeholder, $html, $attrs_json );

$this->assertStringContainsString( 'data-wp-block-name="', $enhanced, 'Sanity check: block-name attribute should exist.' );
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test asserts attribute that method never adds

High Severity

The test test_set_block_attributes_tag_api_preserves_dollar_signs asserts that the output contains data-wp-block-name=", but the method being tested (set_block_attributes_tag_api) never adds that attribute. The data-wp-block-name attribute is only set by process_block_with_html_tag_api via WP_HTML_Tag_Processor::set_attribute(). This causes the test to always fail at the "sanity check" assertion on line 176, meaning the actual dollar-sign assertion on line 178 is never reached, making the test unable to verify the fix it was written for.

Fix in Cursor Fix in Web

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/wp-nextjs-app

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 83.62 KB (🟢 -42.45 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@cursor
Copy link
Copy Markdown

cursor bot commented Mar 31, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/headstartwp

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@github-actions
Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Analysis for @10up/wp-nextjs-app

This analysis was generated by the Next.js Bundle Analysis action. 🤖

🎉 Global Bundle Size Decreased

Page Size (compressed)
global 83.62 KB (🟢 -42.45 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

@nicholasio nicholasio merged commit 03336bc into develop Apr 1, 2026
20 checks passed
@nicholasio nicholasio deleted the fix/allow-dollar-sign-custom-blocks branch April 1, 2026 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants