summaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorArne H Juul <arnej@yahoo-inc.com>2016-12-02 11:02:57 +0000
committerArne H Juul <arnej@yahoo-inc.com>2016-12-02 11:02:57 +0000
commitdca17d4edfab10c8514aba219e28480e63f21b1c (patch)
tree634ff09e324ed5cf7ae81cc73c384ddfbe98c81e /staging_vespalib
parent9651729341e8cce9d2c4e529ebc4bf070ac61648 (diff)
actually escape URL components
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/net/generic_state_handler.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/net/generic_state_handler.cpp b/staging_vespalib/src/vespa/vespalib/net/generic_state_handler.cpp
index 5b17b1eb307..4b02d586222 100644
--- a/staging_vespalib/src/vespa/vespalib/net/generic_state_handler.cpp
+++ b/staging_vespalib/src/vespa/vespalib/net/generic_state_handler.cpp
@@ -7,8 +7,28 @@ namespace vespalib {
namespace {
+// escape a path component in the URL
+// (needed to avoid java.net.URI throwing an exception)
+
vespalib::string url_escape(const vespalib::string &item) {
- return item;
+ static const char hexdigits[] = "0123456789ABCDEF";
+ vespalib::string r;
+ r.reserve(item.size());
+ for (const char c : item) {
+ if ( ('a' <= c && c <= 'z')
+ || ('0' <= c && c <= '9')
+ || ('A' <= c && c <= 'Z')
+ || (c == '_')
+ || (c == '-'))
+ {
+ r.append(c);
+ } else {
+ r.append('%');
+ r.append(hexdigits[0xF & (c >> 4)]);
+ r.append(hexdigits[0xF & c]);
+ }
+ }
+ return r;
}
class Url {