deliciousbrains / better-search-replace

A simple plugin for updating URLs or other text in a database.
https://bettersearchreplace.com
GNU General Public License v3.0
86 stars 36 forks source link

Text with escaped slashes etc in Block text fields can't be found #66

Open noahkuhn opened 4 years ago

noahkuhn commented 4 years ago

This is the first time I've used the new Blocks capability on a build. I'm creating my blocks via ACF Pro. Within some of the blocks I've created, I have simple WYSIWYG text fields, and within those, obviously you can create links or add images etc.

When that data is saved to the database, it gets saved in a JSON object and HTML within the text field has parts that get escaped. Seems primarily to be the slashes, probably other things as well. So for example:

<!-- wp:acf/introduction { "id": "block_5e8cb5c59c4b3", "name": "acf\/introduction", "data": { "text": "<a href=\"http:\/\/testwebsite.test\/part-one\/part-two\/\">Learn More<\/a>", "_text": "field_5e6900ce032f4", } } /-->

So now I go to do a find replace on http://testwebsite.test and it doesn't find it because it's been escaped. Seems that Better Search & Replace needs to be tweaked such that escaped slashes (and whatever else is relevant) are sorted out and you can find things within these Block content fields.

erikyo commented 4 months ago

First of all, thank you for your plugin, it has often been useful to me.

However, I would like to mention that I also find myself having to replace URLs multiple times if they contain slashes due to the escaped version in the JSON. It would be great to have an option (maybe under "ADDITIONAL SETTINGS") that adds this feature, for example, a "Search also the escaped string"

I add here a test case, the recently introduced wp_font_face posts type that copy the site url into the saved json, you can find it with SELECT 'post_content' FROM 'wp_posts' WHERE 'post_type' = 'wp_font_face' (after saving a custom font)

{
    "fontFamily": "exampleFont",
    "fontStyle": "normal",
    "fontWeight": "300",
    "src": "https:\/\/mywebsite.com\/wp-content\/uploads\/fonts\/example.woff"
}