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
89 stars 36 forks source link

Case insensitive setting now works for serialized data #112

Closed eriktorsner closed 6 months ago

eriktorsner commented 6 months ago

Resolves: DELI-1014

In BSR & BSR-PRO v1.4.6, we introduced an early return to skip out of recursive search/replace in serialized data if the target $data is a string (as opposed to object or array) but doesn't contain the search term. However, the early return logic always uses strpos() regardless of what the $case_insensitivesetting is.

In this PR, this is changed so that we select strpos() or stripos() for comparing strings depending on the value of $case_insensitive.

To test

Using version 1.4.6:

  1. Add serialized data containing uppercase text to the options table: wp option update --format=json foobar '{"value":"UPPERCASE"}'
  2. In BSR, do a dry-run search for "uppercase" in wp_options with Case-Insensitive checked.
  3. Note that it reports zero hits.
  4. Run the search/replace anyway.
  5. Verify that nothing was changed and that foobar still contains "UPPERCASE": wp option get foobar

Using this PR:

  1. In BSR, do a dry-run search for "uppercase" in wp_options with Case-Insensitive unchecked.
  2. Note that it reports 0 hits.
  3. Do another dry-run search for "uppercase" in wp_options, this time with Case-Insensitive checked.
  4. Note that it now reports 1 hit.
  5. Run the search/replace.
  6. Verify that "UPPERCASE" was replaced with the new value: wp option get foobar