diff --git a/lib/encode.cpp b/lib/encode.cpp index 66a085a2..79ce8b4d 100644 --- a/lib/encode.cpp +++ b/lib/encode.cpp @@ -91,14 +91,14 @@ namespace Encodings{ } /// urlencodes std::string data, leaving only the characters A-Za-z0-9~!&()' alone. - std::string URL::encode(const std::string &c){ + std::string URL::encode(const std::string &c, const std::string &ign){ std::string escaped = ""; int max = c.length(); 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] == '\'')){ + 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/encode.h b/lib/encode.h index a604bb42..6d4b8028 100644 --- a/lib/encode.h +++ b/lib/encode.h @@ -20,7 +20,7 @@ namespace Encodings { /// urldecodes std::string data, parsing out both %-encoded characters and +-encoded spaces. static std::string decode(const std::string & in); /// urlencodes std::string data, leaving only the characters A-Za-z0-9~!&()' alone. - static std::string encode(const std::string & c); + static std::string encode(const std::string & c, const std::string &ign = ""); }; diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index 6f1caee9..3c619df5 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -176,9 +176,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; }