From 2de35c1bd5ec5ca51bb32a855d550c1259926cb7 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 7 May 2021 08:31:27 +0200 Subject: [PATCH] Cleanup for push rules escaping --- lib/http/client.cpp | 49 +++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/lib/http/client.cpp b/lib/http/client.cpp index d7f3788d4..0d7d187e0 100644 --- a/lib/http/client.cpp +++ b/lib/http/client.cpp @@ -576,10 +576,12 @@ Client::get_pushrules(const std::string &scope, const std::string &ruleId, Callback cb) { - get("/client/r0/pushrules/" + scope + "/" + kind + "/" + ruleId, - [cb](const mtx::pushrules::PushRule &res, - HeaderFields, - RequestErr err) { cb(res, err); }); + get( + "/client/r0/pushrules/" + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + mtx::client::utils::url_encode(ruleId), + [cb](const mtx::pushrules::PushRule &res, HeaderFields, RequestErr err) { + cb(res, err); + }); } void @@ -588,7 +590,8 @@ Client::delete_pushrules(const std::string &scope, const std::string &ruleId, ErrCallback cb) { - delete_("/client/r0/pushrules/" + scope + "/" + kind + "/" + + delete_("/client/r0/pushrules/" + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + mtx::client::utils::url_encode(ruleId), cb); } @@ -610,11 +613,12 @@ Client::put_pushrules(const std::string &scope, if (!after.empty()) params.emplace("after", after); - put("/client/r0/pushrules/" + scope + "/" + kind + "/" + - mtx::client::utils::url_encode(ruleId) + "?" + - mtx::client::utils::query_params(params), - rule, - cb); + std::string path = "/client/r0/pushrules/" + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + + mtx::client::utils::url_encode(ruleId); + if (!params.empty()) + path += "?" + mtx::client::utils::query_params(params); + put(path, rule, cb); } void @@ -624,8 +628,9 @@ Client::get_pushrules_enabled(const std::string &scope, Callback cb) { get( - "/client/r0/pushrules/" + scope + "/" + kind + "/" + - mtx::client::utils::url_encode(ruleId) + "/enabled", + "/client/r0/pushrules/" + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + mtx::client::utils::url_encode(ruleId) + + "/enabled", [cb](const mtx::pushrules::Enabled &res, HeaderFields, RequestErr err) { cb(res, err); }); } @@ -636,7 +641,9 @@ Client::put_pushrules_enabled(const std::string &scope, bool enabled, ErrCallback cb) { - put("/client/r0/pushrules/" + scope + "/" + kind + "/" + + put("/client/r0/pushrules/" + + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + mtx::client::utils::url_encode(ruleId) + "/enabled", {enabled}, cb); @@ -648,11 +655,13 @@ Client::get_pushrules_actions(const std::string &scope, const std::string &ruleId, Callback cb) { - get("/client/r0/pushrules/" + scope + "/" + kind + "/" + - mtx::client::utils::url_encode(ruleId) + "/actions", - [cb](const mtx::pushrules::actions::Actions &res, - HeaderFields, - RequestErr err) { cb(res, err); }); + get( + "/client/r0/pushrules/" + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + mtx::client::utils::url_encode(ruleId) + + "/actions", + [cb](const mtx::pushrules::actions::Actions &res, HeaderFields, RequestErr err) { + cb(res, err); + }); } void @@ -662,7 +671,9 @@ Client::put_pushrules_actions(const std::string &scope, const mtx::pushrules::actions::Actions &actions, ErrCallback cb) { - put("/client/r0/pushrules/" + scope + "/" + kind + "/" + + put("/client/r0/pushrules/" + + mtx::client::utils::url_encode(scope) + "/" + + mtx::client::utils::url_encode(kind) + "/" + mtx::client::utils::url_encode(ruleId) + "/actions", actions, cb);