From ae01eb5dedc30641f01c4fb611cd5a11d7fcac5a Mon Sep 17 00:00:00 2001 From: Armstrong Date: Thu, 26 Sep 2019 10:06:09 +0800 Subject: [PATCH] fix url decode (#256) * urldecode: should always unescaped chars --- examples/simple_example/api_v1_ApiTest.cc | 9 +++++++-- examples/simple_example_test/main.cc | 1 + lib/src/Utilities.cc | 19 +++---------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/examples/simple_example/api_v1_ApiTest.cc b/examples/simple_example/api_v1_ApiTest.cc index bd58712c..1f32762a 100644 --- a/examples/simple_example/api_v1_ApiTest.cc +++ b/examples/simple_example/api_v1_ApiTest.cc @@ -396,7 +396,12 @@ void ApiTest::formTest(const HttpRequestPtr &req, { auto parameters = req->getParameters(); Json::Value ret; - if (parameters["k1"] == "1" && parameters["k2"] == "安") + ret["k1"] = parameters["k1"]; + ret["k2"] = parameters["k2"]; + ret["k3"] = parameters["k3"]; + + if (parameters["k1"] == "1" && parameters["k2"] == "安" && + parameters["k3"] == "test@example.com") { ret["result"] = "ok"; } @@ -406,4 +411,4 @@ void ApiTest::formTest(const HttpRequestPtr &req, } auto resp = HttpResponse::newHttpJsonResponse(ret); callback(resp); -} \ No newline at end of file +} diff --git a/examples/simple_example_test/main.cc b/examples/simple_example_test/main.cc index 2b58068a..f190f0c9 100644 --- a/examples/simple_example_test/main.cc +++ b/examples/simple_example_test/main.cc @@ -901,6 +901,7 @@ void doTest(const HttpClientPtr &client, req->setPath("/api/v1/apitest/form"); req->setParameter("k1", "1"); req->setParameter("k2", "安"); + req->setParameter("k3", "test@example.com"); client->sendRequest(req, [=](ReqResult result, const HttpResponsePtr &resp) { if (result == ReqResult::Ok) diff --git a/lib/src/Utilities.cc b/lib/src/Utilities.cc index 333d5232..9714b120 100644 --- a/lib/src/Utilities.cc +++ b/lib/src/Utilities.cc @@ -505,22 +505,9 @@ std::string urlDecode(const char *begin, const char *end) x2 = x2 - 'A' + 10; } hex = x1 * 16 + x2; - if (!((hex >= 48 && hex <= 57) || // 0-9 - (hex >= 97 && hex <= 122) || // a-z - (hex >= 65 && hex <= 90) || // A-Z - //[$-_.+!*'(),] [$&+,/:;?@] - hex == 0x21 || hex == 0x24 || hex == 0x26 || - hex == 0x27 || hex == 0x28 || hex == 0x29 || - hex == 0x2a || hex == 0x2b || hex == 0x2c || - hex == 0x2d || hex == 0x2e || hex == 0x2f || - hex == 0x3A || hex == 0x3B || hex == 0x3f || - hex == 0x40 || hex == 0x5f)) - { - result += char(hex); - i += 2; - } - else - result += '%'; + + result += char(hex); + i += 2; } else {