Skip to content

Commit 1e74a46

Browse files
schlesseraclaude
andauthored
Correct the docs on JSON-encoded URLs (#251)
Since #213, search-replace also replaces the JSON-encoded form of the search string, so the extra run with escaped slashes added in #248 is not needed. Document the automatic handling instead, and note that it does not apply with --regex. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54d3e08 commit 1e74a46

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ multisite, this will just be the tables for the current site unless
2323
Search/replace intelligently handles PHP serialized data, and does not
2424
change primary key values.
2525

26-
Note: URLs stored inside JSON-encoded data (such as block attributes or
27-
form configurations) often have forward slashes escaped with backslashes
28-
(e.g. `https:\/\/example.com`). Standard search/replace with unescaped
29-
URLs will not match these. To replace URLs in JSON-encoded strings, run
30-
an additional search/replace with escaped slashes (e.g.
31-
`wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'`).
26+
The JSON-encoded form of the search string is replaced as well, so a
27+
search for `https://example.com` also matches `https:\/\/example.com`
28+
in JSON stored in the database. This does not apply with `--regex`,
29+
where the pattern itself has to account for escaped slashes.
3230

3331
Tables without a primary key are skipped. To check whether a table has a
3432
primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
@@ -151,9 +149,6 @@ the Key column.
151149
# Search and replace but skip one column
152150
$ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid
153151

154-
# Search/replace JSON-encoded URLs (where forward slashes are escaped with backslashes)
155-
$ wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'
156-
157152
# Run search/replace operation but dont save in database
158153
$ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run
159154

‎src/Search_Replace_Command.php‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ class Search_Replace_Command extends WP_CLI_Command {
140140
* Search/replace intelligently handles PHP serialized data, and does not
141141
* change primary key values.
142142
*
143-
* Note: URLs stored inside JSON-encoded data (such as block attributes or
144-
* form configurations) often have forward slashes escaped with backslashes
145-
* (e.g. `https:\/\/example.com`). Standard search/replace with unescaped
146-
* URLs will not match these. To replace URLs in JSON-encoded strings, run
147-
* an additional search/replace with escaped slashes (e.g.
148-
* `wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'`).
143+
* The JSON-encoded form of the search string is replaced as well, so a
144+
* search for `https://example.com` also matches `https:\/\/example.com`
145+
* in JSON stored in the database. This does not apply with `--regex`,
146+
* where the pattern itself has to account for escaped slashes.
149147
*
150148
* Tables without a primary key are skipped. To check whether a table has a
151149
* primary key, run `wp db query 'DESCRIBE <table>'` and look for 'PRI' in
@@ -268,9 +266,6 @@ class Search_Replace_Command extends WP_CLI_Command {
268266
* # Search and replace but skip one column
269267
* $ wp search-replace 'http://example.test' 'http://example.com' --skip-columns=guid
270268
*
271-
* # Search/replace JSON-encoded URLs (where forward slashes are escaped with backslashes)
272-
* $ wp search-replace 'https:\/\/example.com' 'https:\/\/example.test'
273-
*
274269
* # Run search/replace operation but dont save in database
275270
* $ wp search-replace 'foo' 'bar' wp_posts wp_postmeta wp_terms --dry-run
276271
*

0 commit comments

Comments
 (0)