From f958215ea86da8c0e8f5e03ed0fe75d716702210 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Wed, 16 Jan 2019 04:54:35 -0500 Subject: [PATCH] Fix --proxy parsing --- src/net/tools/naive/naive_proxy_bin.cc | 11 ++++------- tests/basic.sh | 10 +++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/net/tools/naive/naive_proxy_bin.cc b/src/net/tools/naive/naive_proxy_bin.cc index 997065aca0..719e90d6a6 100644 --- a/src/net/tools/naive/naive_proxy_bin.cc +++ b/src/net/tools/naive/naive_proxy_bin.cc @@ -242,13 +242,11 @@ void GetCommandLineFromConfig(const base::FilePath& config_path, } std::string GetProxyFromURL(const GURL& url) { - auto shp = url::SchemeHostPort(url); - if (url::DefaultPortForScheme(shp.scheme().c_str(), shp.scheme().size()) == - url::PORT_UNSPECIFIED) { - return shp.Serialize() + ":" + base::IntToString(shp.port()); - } else { - return shp.Serialize(); + std::string str = url.GetWithEmptyPath().spec(); + if (str.size() && str.back() == '/') { + str.pop_back(); } + return str; } bool ParseCommandLine(const CommandLine& cmdline, Params* params) { @@ -298,7 +296,6 @@ bool ParseCommandLine(const CommandLine& cmdline, Params* params) { return false; } params->proxy_url = GetProxyFromURL(url_no_auth); - params->proxy_url.erase(); params->proxy_user = url.username(); params->proxy_pass = url.password(); } diff --git a/tests/basic.sh b/tests/basic.sh index 950242b82d..a6c22516a8 100755 --- a/tests/basic.sh +++ b/tests/basic.sh @@ -40,19 +40,23 @@ echo '{"listen":"socks://127.0.0.1:61080","log":""}' >/tmp/config.json test_naive 'Config file' socks5h://127.0.0.1:61080 '/tmp/config.json' rm -f /tmp/config.json -test_naive 'Trivial - scheme only' socks5h://127.0.0.1:1080 \ +test_naive 'Trivial - listen scheme only' socks5h://127.0.0.1:1080 \ '--log --listen=socks://' -test_naive 'Trivial - no host' socks5h://127.0.0.1:61080 \ +test_naive 'Trivial - listen no host' socks5h://127.0.0.1:61080 \ '--log --listen=socks://:61080' -test_naive 'Trivial - no port' socks5h://127.0.0.1:1080 \ +test_naive 'Trivial - listen no port' socks5h://127.0.0.1:1080 \ '--log --listen=socks://127.0.0.1' test_naive 'SOCKS-SOCKS' socks5h://127.0.0.1:11080 \ '--log --listen=socks://:11080 --proxy=socks://127.0.0.1:21080' \ '--log --listen=socks://:21080' +test_naive 'SOCKS-SOCKS - proxy no port' socks5h://127.0.0.1:11080 \ + '--log --listen=socks://:11080 --proxy=socks://127.0.0.1' \ + '--log --listen=socks://:1080' + test_naive 'SOCKS-HTTP' socks5h://127.0.0.1:11080 \ '--log --listen=socks://:11080 --proxy=http://127.0.0.1:28080' \ '--log --listen=http://:28080'