about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-08-03T18·36+0200
committerEelco Dolstra <edolstra@gmail.com>2018-08-03T19·20+0200
commit848a9375c3753202bf53defda469ca5d7538e135 (patch)
tree39e7947e00599e851ff2d5b102a426541df6523a
parent4e7d5f660cec6da3a432c726dfe7a579c7581c79 (diff)
Support escaping in store URIs
-rw-r--r--src/libstore/store-api.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 1854353828df..7a4a5f5eb85d 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -844,8 +844,24 @@ ref<Store> openStore(const std::string & uri_,
     if (q != std::string::npos) {
         for (auto s : tokenizeString<Strings>(uri.substr(q + 1), "&")) {
             auto e = s.find('=');
-            if (e != std::string::npos)
-                params[s.substr(0, e)] = s.substr(e + 1);
+            if (e != std::string::npos) {
+                auto value = s.substr(e + 1);
+                std::string decoded;
+                for (size_t i = 0; i < value.size(); ) {
+                    if (value[i] == '%') {
+                        if (i + 2 >= value.size())
+                            throw Error("invalid URI parameter '%s'", value);
+                        try {
+                            decoded += std::stoul(std::string(value, i + 1, 2), 0, 16);
+                            i += 3;
+                        } catch (...) {
+                            throw Error("invalid URI parameter '%s'", value);
+                        }
+                    } else
+                        decoded += value[i++];
+                }
+                params[s.substr(0, e)] = decoded;
+            }
         }
         uri = uri_.substr(0, q);
     }