From 28fd36f0df5411edc5c0177c5034a4dab66e7b1d Mon Sep 17 00:00:00 2001 From: Michael Vrable Date: Tue, 17 Jul 2007 16:29:14 -0700 Subject: [PATCH] Add string un-escaping, and fix the statcache reader to use it. --- format.cc | 32 ++++++++++++++++++++++++++++++++ format.h | 1 + statcache.cc | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/format.cc b/format.cc index 1fccf4e..9e985af 100644 --- a/format.cc +++ b/format.cc @@ -39,6 +39,38 @@ string uri_encode(const string &in) return out; } +/* Decoding of strings produced by uri_encode. */ +string uri_decode(const string &in) +{ + char *buf = new char[in.size() + 1]; + + const char *input = in.c_str(); + char *output = buf; + + while (*input != '\0') { + if (*input == '%') { + char hexbuf[4]; + if (isxdigit(input[1]) && isxdigit(input[2])) { + hexbuf[0] = input[1]; + hexbuf[1] = input[2]; + hexbuf[2] = '\0'; + *output++ = strtol(hexbuf, NULL, 16); + input += 3; + } else { + input++; + } + } else { + *output++ = *input++; + } + } + + *output = '\0'; + + string result(buf); + delete buf; + return result; +} + /* Return the string representation of an integer. */ string encode_int(long long n) { diff --git a/format.h b/format.h index 519bceb..7cb9bf4 100644 --- a/format.h +++ b/format.h @@ -13,6 +13,7 @@ #include std::string uri_encode(const std::string &in); +std::string uri_decode(const std::string &in); std::string encode_int(long long n); void dict_output(std::ostream &o, std::map dict); diff --git a/statcache.cc b/statcache.cc index cccbf5b..5a8d26c 100644 --- a/statcache.cc +++ b/statcache.cc @@ -125,12 +125,13 @@ void StatCache::ReadNext() old_checksum = ""; old_contents.clear(); - /* First, read in the filename. TODO: Unescaping. */ + /* First, read in the filename. */ getline(cache, old_name); if (!cache) { end_of_cache = true; return; } + old_name = uri_decode(old_name); /* Start reading in the fields which follow the filename. */ string field = ""; -- 2.20.1