Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escaped URLs are not found #365

Open
GigiSan opened this issue Jul 12, 2021 · 4 comments
Open

Escaped URLs are not found #365

GigiSan opened this issue Jul 12, 2021 · 4 comments

Comments

@GigiSan
Copy link

GigiSan commented Jul 12, 2021

Hello everyone,

Since v4 it looks like escaped URLs are not found properly.

Consider a row with this value:
{"action":"console","days":90,"prev":{"country":"all","profile":"https:\/\/testdomain.com\/"}}

If I just search for testdomain.com and replace it with anotherdomain.com, this row gets found correctly.

But if I have to replace the full URL because, for example, I have to change protocol and turn https:\/\/testdomain.com into http:\/\/anotherdomain.com, the search string is not found in this case.

Some more deatils on the matter:

  • I'm a long time SRDB user and I'm 100% sure this wasn't an issue in v3
  • I'm currently on PHP 7.4.19 and SRDB v4.1.3
  • The behavior mentioned above is the same for both GUI and CLI

If you need any further info please let me know.
Meanwhile, thanks in advance for your time and have a nice day!
Regards,
-Gigi

@GigiSan GigiSan changed the title Escaped URL are not found Escaped URLs are not found Jul 12, 2021
@itajackass
Copy link

same problem for me

@amelhorn
Copy link

We can replicate the issue also - any url containing a '/' or '' is no longer found in version 4

@GigiSan
Copy link
Author

GigiSan commented Aug 30, 2021

UPDATE: The web version seems to have some problems with the '/' delimiters it prepends/appends to the regex, I actually modified those to '#' in the srdb code.


I have found a temporary solution, maybe even permanent for me, which is using regex, as regex search-replace doesn't seem to be affected by the problem.

I will give you the example I used, in case someone has a similar requirement:

Search:
(http(s)?)((\:\/\/)|(\:\\\/\\\/)|((\:|\%3A)\%2F\%2F))(testdomain\.com)
(check use regex, then Case insensitive and Multiline flags)

Replace:
http$3anotherdomain.com

This will replace:

https://testdomain.com
http://testdomain.com
https:\/\/testdomain.com
http:\/\/testdomain.com
https:%2F%2Ftestdomain.com
http:%2F%2Ftestdomain.com
https%3A%2F%2Ftestdomain.com
http%3A%2F%2Ftestdomain.com

respectively with:

http://anotherdomain.com
http://anotherdomain.com
http:\/\/anotherdomain.com
http:\/\/anotherdomain.com
http:%2F%2Fanotherdomain.com
http:%2F%2Fanotherdomain.com
http%3A%2F%2Fanotherdomain.com
http%3A%2F%2Fanotherdomain.com

Which makes WordPress sites imported locally work flawlessly no matter how many plugins there are. 🙂
You can find an explanation of the regex HERE. Hope this helps someone while a solution is found.

@mkjmdski
Copy link

@GigiSan solution works great! The tricky part is to pass regex that complex from bash script level. I've wrote a simple function which is responsible for running search-and-replace from command line

First argument is old url we want to replace, second the new one and third the protocol (http or https) we want to start using.

run_replace() {
    existing_domain="$1"
    new_domain="${2}"
    new_protocol="${3}"
    srdb_root_path='/usr/local/lib/search-and-replace'
    if echo $PHP_VERSION | grep -q '5.6' || echo $PHP_VERSION | grep -q '7.1'; then
        srdb_path="${srdb_root_path}/3.1"
    else
        srdb_path="${srdb_root_path}/4.1"
    fi
    # regex from: https://github.com/interconnectit/Search-Replace-DB/issues/365
    php "${srdb_path}/srdb.cli.php" \
        --host $MYSQL_HOSTNAME \
        --user $MYSQL_USERNAME \
        --pass $MYSQL_PASS \
        --port $MYSQL_PORT \
        --name $MYSQL_DATABASE \
        --search "#$(echo '(http(s)?)((\\:\\/\\/)|(\\:\\\\\\/\\\\\\/)|((\\:|\\%3A)\\%2F\\%2F))('"$(echo $existing_domain | sed 's|\.|\\\\\.|g')"')')#" \
        --replace $(echo $new_protocol'$3'$new_domain) \
        --debug --verbose --regex
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants