go-search-replace icon indicating copy to clipboard operation
go-search-replace copied to clipboard

Unable to handle escaped full URLs

Open JeffCleverley opened this issue 3 years ago • 0 comments

One of the primary use cases of this would be to rewrite domain urls in the db from http to https

I see you have several tickets on this:

https://github.com/Automattic/go-search-replace/issues/3 https://github.com/Automattic/go-search-replace/issues/2 https://github.com/Automattic/go-search-replace/issues/1

This tool covers:

http://example.com -> https://example.com

but is unable to handle the escaped variants:

http:\/\/example.com -> https:\/\/example.com

Re using delimiters for things like swapping domains:

/example.com -> /newdomain.com

And that would cover most use cases, swapping domains, filepaths etc

But none of this works for swapping http version of domain url to https version of domain url and compensating for escaped urls which are quite commonly found in WP databases.

If you try to pass in the string including escaped slashes, the tool autoescapes these and targets the wrong string instead:

root@may31-devbeta-jeff-buildtest:~# echo "input:"; cat test.sql && cat test.sql | go-search-replace http:\/\/example.com https:\/\/example.com >totest.sql; echo "output:" && cat totest.sql
input:
http://example.com
http:\/\/example.com
output:
https://example.com
http:\/\/example.com

See this has been rewritten instead:

http://example.com -> https://example.com 

And the string with the escaped url is untouched.

This is similar behaviour to interconnectit search-replace, but with that tool you can escape the backslashes like so on the inputs....

So to target escaped urls with interconnectit tool you use:

http:\\\/\/example.com https:\\\/\/example.com

But that doesn't work here:

root@may31-devbeta-jeff-buildtest:~# echo "input:"; cat test.sql && cat test.sql | go-search-replace http:\\\/\/example.com https:\\\/\/example.com >totest.sql; echo "output:" && cat totest.sql
input:
http://example.com
http:\/\/example.com
Invalid <from> URL, minimum length is 4
output:

JeffCleverley avatar Jun 08 '21 09:06 JeffCleverley