go-search-replace
go-search-replace copied to clipboard
Corrupted data if serialized var contains a serialized string that gets changed
It is an edge case and the first time I've seen/noticed it so I don't expect a fix, and it's probably out of scope for this tool, but since I ran into it: Having
serialize([ 'something' => 'a:1:{s:3:"url";s:20:"https://example.org/";}'])
and replacing the domain:
echo 'a:1:{s:4:\"test\";s:44:\"a:1:{s:3:\"url\";s:20:\"https://example.org/\";}\";}' | ./go-search-replace_linux_amd64 example.org test.com
yields
a:1:{s:4:\"test\";s:44:\"a:1:{s:3:\"url\";s:17:\"https://test.com/\";}\";}
when it should be
a:1:{s:4:\"test\";s:41:\"a:1:{s:3:\"url\";s:17:\"https://test.com/\";}\";}
because the length only gets fixed in the "inner" string. I don't see an easy fix with the way it's currently built because you'd have to backtrack all the way to the beginning to be sure that you're not inside a nested serialization, but maybe I'm missing something.