summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2009-09-12 20:58:06 (UTC)
committer Michael Krelin <hacker@klever.net>2009-09-13 11:44:38 (UTC)
commitc5e2a9ce7d7836adaa284dee30b70e04081b0d01 (patch) (side-by-side diff)
tree1be9052fcc77047d1b387d86a7da0c653db10ce3
parent570ab021e0dcf507ecd6b7118151fb90feeab779 (diff)
downloadlibopkele-c5e2a9ce7d7836adaa284dee30b70e04081b0d01.zip
libopkele-c5e2a9ce7d7836adaa284dee30b70e04081b0d01.tar.gz
libopkele-c5e2a9ce7d7836adaa284dee30b70e04081b0d01.tar.bz2
minor url_decode improvements
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--lib/util.cc7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/util.cc b/lib/util.cc
index 4028697..02f9473 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -196,53 +196,52 @@ namespace opkele {
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;
- if(i==ie)
+ if((++i)==ie)
throw failed_conversion(OPKELE_CP_ "trailing percent in the url-encoded string");
- tmp[0] = *(i++);
- if(i==ie)
+ 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) {
if(p!=str.length())
rv.append(str,p,str.length()-p);
return rv;
}