Replace corrupts serialized data if the search and replace are of different length
To reproduce:
php -r 'echo serialize("aaaaabbbbbbbbbbaaaaa"), PHP_EOL;' > test.txt
cat test.txt | ./go-search-replace bbbbbbbbbb ccccc
cat test.txt | ./go-search-replace bbbbbbbbbb ccccccccccccccc
Expected result:
s:15:"aaaaacccccaaaaa";
s:25:"aaaaacccccccccccccccaaaaa";
Actual result:
s:20:"aaaaacccccaaaaa";
s:20:"aaaaacccccccccccccccaaaaa";
This is because go-search-replace expects the quote marks to be escaped. Whether that's a bug or not I don't know.
$ php -r 'echo addslashes( serialize("aaaaabbbbbbbbbbaaaaa") ), PHP_EOL;' > test.txt
$ cat test.txt
s:20:\"aaaaabbbbbbbbbbaaaaa\";
$ cat test.txt | go-search-replace bbbbbbbbbb ccccc
s:15:\"aaaaacccccaaaaa\";
$ cat test.txt | go-search-replace bbbbbbbbbb ccccccccccccccc
s:25:\"aaaaacccccccccccccccaaaaa\";
But then it does not work on statements like
INSERT INTO `wp_options` (option_name, option_value) VALUES ('test', 's:15:"aaaaacccccaaaaa";');
Double quotes inside single quotes do not have to be escaped.
I think WP always escapes the quotes, but if you're seeing otherwise it should be fine to change the regex
https://github.com/Automattic/go-search-replace/blob/master/search-replace.go#L17-L18
The reason it behaves like that is that mysqldump will escape double quotes unnecessarily, therefore it keeps this behavior, since unescaped double quotes indicate other data, that should generally not be replaced by go-search-replace