From e49f89c7827c895f5f98a70a45519e4ad5128ae2 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 23 Aug 2018 12:38:58 +0200 Subject: [PATCH] Improved URL encode/decode behaviour --- lib/downloader.cpp | 2 +- lib/encode.cpp | 4 ++-- lib/http_parser.cpp | 14 +++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/downloader.cpp b/lib/downloader.cpp index b2ace65c..e892355d 100644 --- a/lib/downloader.cpp +++ b/lib/downloader.cpp @@ -108,7 +108,7 @@ namespace HTTP{ H.SetHeader("Host", proxyUrl.host); } }else{ - H.url = "/" + Encodings::URL::encode(link.path); + H.url = "/" + Encodings::URL::encode(link.path, "/:=@[]"); if (link.args.size()){H.url += "?" + link.args;} if (link.port.size()){ H.SetHeader("Host", link.host + ":" + link.port); diff --git a/lib/encode.cpp b/lib/encode.cpp index 8f8b4e13..7af00bfb 100644 --- a/lib/encode.cpp +++ b/lib/encode.cpp @@ -97,8 +97,8 @@ namespace Encodings{ for (int i = 0; i < max; i++){ if (('0' <= c[i] && c[i] <= '9') || ('a' <= c[i] && c[i] <= 'z') || ('A' <= c[i] && c[i] <= 'Z') || - (c[i] == '$' || c[i] == '-' || c[i] == '_' || c[i] == '.' || c[i] == ',' || c[i] == '!' || - c[i] == '*' || c[i] == '(' || c[i] == ')' || c[i] == '/' || c[i] == '\'') || (ign.size() && ign.find(c[i]) != std::string::npos)){ + (c[i] == '$' || c[i] == '-' || c[i] == '_' || c[i] == '.' || c[i] == ',' || c[i] == '!' || c[i] == '~' || c[i] == ';' || + c[i] == '*' || c[i] == '(' || c[i] == ')' || c[i] == '\'') || (ign.size() && ign.find(c[i]) != std::string::npos)){ escaped.append(&c[i], 1); }else{ if (c[i] == ' '){ diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index 44daa96f..c472a8d3 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -135,11 +135,7 @@ HTTP::URL::URL(const std::string &url){ port = host; host = ""; } - EXTREME_MSG("URL host: %s", host.c_str()); - EXTREME_MSG("URL protocol: %s", protocol.c_str()); - EXTREME_MSG("URL port: %s", port.c_str()); - EXTREME_MSG("URL path: %s", path.c_str()); - EXTREME_MSG("URL args: %s", args.c_str()); + EXTREME_MSG("URL: %s", getUrl().c_str()); } /// Returns the port in numeric format @@ -184,9 +180,9 @@ std::string HTTP::URL::getUrl() const{ } if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;} ret += "/"; - if (path.size()){ret += Encodings::URL::encode(path, "=");} + if (path.size()){ret += Encodings::URL::encode(path, "/:=@[]");} if (args.size()){ret += "?" + args;} - if (frag.size()){ret += "#" + Encodings::URL::encode(frag, "=");} + if (frag.size()){ret += "#" + Encodings::URL::encode(frag, "/:=@[]#?&");} return ret; } @@ -210,7 +206,7 @@ std::string HTTP::URL::getProxyUrl() const{ } if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;} ret += "/"; - if (path.size()){ret += Encodings::URL::encode(path);} + if (path.size()){ret += Encodings::URL::encode(path, "/:=@[]");} if (args.size()){ret += "?" + args;} return ret; } @@ -233,7 +229,7 @@ std::string HTTP::URL::getBareUrl() const{ } if (port.size() && getPort() != getDefaultPort()){ret += ":" + port;} ret += "/"; - if (path.size()){ret += Encodings::URL::encode(path);} + if (path.size()){ret += Encodings::URL::encode(path, "/:=@[]");} return ret; }