author | Michael Krelin <hacker@klever.net> | 2008-09-22 20:08:35 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-09-22 20:08:35 (UTC) |
commit | 4522de61114018633f66492e2e9977cdb3108098 (patch) (side-by-side diff) | |
tree | 2af460f9269163320098476d484dee867c4e8138 /lib/util.cc | |
parent | 767b9926a3b2a2ab000415cc5d36df84dd90f13f (diff) | |
download | libopkele-4522de61114018633f66492e2e9977cdb3108098.zip libopkele-4522de61114018633f66492e2e9977cdb3108098.tar.gz libopkele-4522de61114018633f66492e2e9977cdb3108098.tar.bz2 |
A couple of bugfixes
- added missing 'return' statement to the forward_iterator_proxy operator=()
- made temporary non-static for thread safety in url_decode()
Thanks to Masato Kataoka of orenosv project
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | lib/util.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/util.cc b/lib/util.cc index a46ba2a..249eeed 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -189,56 +189,56 @@ namespace opkele { __url_encoder(string& r) : rv(r) { } result_type operator()(argument_type c) { if(isrfc3986unreserved(c)) rv += c; else{ char tmp[4]; snprintf(tmp,sizeof(tmp),"%%%02X", (c&0xff)); rv += tmp; } } }; string url_encode(const string& str) { string rv; for_each(str.begin(),str.end(), __url_encoder(rv)); return rv; } string url_decode(const string& str) { string rv; back_insert_iterator<string> ii(rv); + char tmp[3]; tmp[2] = 0; for(string::const_iterator i=str.begin(),ie=str.end(); i!=ie;++i) { switch(*i) { case '+': *(ii++) = ' '; break; case '%': ++i; - static char tmp[3] = {0,0,0}; if(i==ie) throw failed_conversion(OPKELE_CP_ "trailing percent in the url-encoded string"); tmp[0] = *(i++); if(i==ie) throw failed_conversion(OPKELE_CP_ "not enough hexadecimals after the percent sign in url-encoded string"); tmp[1] = *i; if(!(isxdigit(tmp[0]) && isxdigit(tmp[1]))) throw failed_conversion(OPKELE_CP_ "non-hex follows percent in url-encoded string"); *(ii++) = (char)strtol(tmp,0,16); break; default: *(ii++) = *i; break; } } return rv; } string attr_escape(const string& str) { static const char *unsafechars = "<>&\n\"'"; string rv; string::size_type p=0; while(true) { string::size_type us = str.find_first_of(unsafechars,p); if(us==string::npos) { |