Skip to content

Handle JSON-encoded URLs in search-replace#213

Merged
swissspidy merged 6 commits intomainfrom
copilot/fix-font-url-update
Mar 11, 2026
Merged

Handle JSON-encoded URLs in search-replace#213
swissspidy merged 6 commits intomainfrom
copilot/fix-font-url-update

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

  • Fix SearchReplacer::run_recursively() to also replace JSON-encoded versions of the search/replace strings
  • Fix Search_Replace_Command::php_handle_col() WHERE clause to also match JSON-encoded search string
  • Fix Search_Replace_Command::sql_handle_col() to also REPLACE JSON-encoded version using a single nested REPLACE(REPLACE(...)) in one table pass, avoiding double-counting rows that match both plain and JSON-encoded forms
  • Fix Search_Replace_Command::sql_handle_col() dry-run COUNT to use a single SELECT COUNT ... WHERE col LIKE '%old%' OR col LIKE '%old_json%' query instead of two separate queries, so rows are counted only once
  • Fix Search_Replace_Command::sql_handle_col() logging: also call log_sql_diff() with $old_json/$new_json when they differ, so JSON-encoded matches appear in --dry-run log output and non-dry-run diff logs
  • Extract json_encode_strip_quotes() public static helper in Search_Replace_Command to reduce duplication; call it from SearchReplacer to eliminate the duplicated inline json_encode + quote-strip logic
  • Handle json_encode() returning false (e.g. invalid UTF-8) gracefully in both files
  • Add a Behat test for the JSON-encoded URL replacement scenario (font data case) covering both SQL and PHP modes
  • Simplify test setup: use wp post create --post_content='...' --post_status=publish --porcelain instead of a PHP eval-file with $wpdb->insert()
Original prompt

This section details on the original issue you should resolve

<issue_title>Domain is not changed for added fonts</issue_title>
<issue_description>## Bug Report

Describe the current, buggy behavior

The command “wp search-replace” does not work as expected. With WordPress 6.5 the Gutenberg Full-Site-Editor got the possibility to add fonts (as direct upload or as direct download from Google Fonts).

If you now change the URL of a WordPress installation with “wp search-replace”, the URL of your own fonts is not adjusted - which means that the font files cannot be loaded.

Describe how other contributors can replicate this bug

  • install a WordPress Site on Domain A
  • Install any font from Google Fonts via the full-site editor in the standard design (twentytwentyfour) or upload any font.
  • Use this installed Font as Default
  • Copy the Site to Domain B
  • use "wp search-replace" to chnage the URL
  • open the Site on Domain B
  • In the browser source code you will then see that the domain of the fonts still refers to domain A

Describe what you would expect as the correct outcome

The domain of the fonts should also be changed via “wp search-replace”.

Let us know what environment you are running this on

OS:	Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112 arm64
Shell:	/bin/zsh
PHP binary:	/Applications/MAMP/bin/php/php8.1.13/bin/php
PHP version:	8.1.13
php.ini used:	/Applications/MAMP/bin/php/php8.1.13/conf/php.ini
MySQL binary:	/Applications/MAMP/Library/bin//mysql
MySQL version:	mysql  Ver 14.14 Distrib 5.7.39, for osx11.0 (x86_64) using  EditLine wrapper
SQL modes:	
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/srueegger/Sites/compresso.ch
WP-CLI packages dir:	
WP-CLI cache dir:	/Users/srueegger/.wp-cli/cache
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.10.0
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@swissspidy</author><body>
What's the exact command that you are using? Have you tried the `--precise` flag?</body></comment_new>
<comment_new><author>@swissspidy</author><body>
FWIW I cannot reproduce this.

I just did `wp search-replace wordpress-cevelop wordpress-develop wp_post*` on my local `wordpress-develop.local` site and the font URLs were replaced as expected in the source code.</body></comment_new>
<comment_new><author>@danielbachhuber</author><body>
My guess is that the URLs are JSON encoded (related https://github.com/wp-cli/search-replace-command/issues/186)</body></comment_new>
<comment_new><author>@ernilambar</author><body>

I can reproduce this issue and it is indeed related to encoded value. When fonts are uploaded, entry is created in posts table and `post_content` looks like this:

{"src":"http://foo.local/wp-content/uploads/fonts/SZc83FzrJKuqFbwMKk6EtUf57DtOmCc.woff2","fontWeight":"400","fontStyle":"normal","fontFamily":""Alex Brush"","preview":"https://s.w.org/images/fonts/17.7/previews/alex-brush/alex-brush-400-normal.svg"}


When I try to generate sql after replacing the domain, eg:

wp search-replace 'http://foo.local' 'http://bar.local' --export=sample.sql


Then value shown above is not updated to new domain.
</body></comment_new>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix font URL not updating with wp search-replace Handle JSON-encoded URLs in search-replace (WordPress font data) Mar 11, 2026
@swissspidy

This comment was marked as resolved.

…ost content

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review March 11, 2026 13:52
@swissspidy swissspidy requested a review from a team as a code owner March 11, 2026 13:52
Copilot AI review requested due to automatic review settings March 11, 2026 13:52
@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Search_Replace_Command.php 90.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions bot added command:search-replace Related to 'search-replace' command scope:testing Related to testing labels Mar 11, 2026
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

…m SearchReplacer

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

… update, and log JSON variants

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy swissspidy changed the title Handle JSON-encoded URLs in search-replace (WordPress font data) Handle JSON-encoded URLs in search-replace Mar 11, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy swissspidy merged commit d07f1fa into main Mar 11, 2026
59 of 60 checks passed
@swissspidy swissspidy deleted the copilot/fix-font-url-update branch March 11, 2026 20:52
@swissspidy swissspidy added this to the 2.1.10 milestone Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:search-replace Related to 'search-replace' command scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Domain is not changed for added fonts

3 participants