Automattic / Automattic/go-search-replace
Unable to handle escaped full URLs
- Dominant language
- Go
- Stars
- 108
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
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 URL, minimum length is 4
output:
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the command shown with test.sql and the go-search-replace entry point, comparing unescaped and escaped URL inputs. Trace how the URL arguments are parsed and identify why escaped slashes target the unescaped URL; done means escaped URLs are replaced while the existing unescaped behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100