summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2009-09-01 19:59:38 (UTC)
committer Michael Krelin <hacker@klever.net>2009-09-01 19:59:38 (UTC)
commitda3fe98e5c75940135fcd9bb45b36eed62d8b4dc (patch) (side-by-side diff)
treeeda546a705a667dd1b62f7eee481b3087fbfdf27
parent34d57b6b55b51e4b489a4cafce8874dec558b600 (diff)
downloadlibopkele-da3fe98e5c75940135fcd9bb45b36eed62d8b4dc.zip
libopkele-da3fe98e5c75940135fcd9bb45b36eed62d8b4dc.tar.gz
libopkele-da3fe98e5c75940135fcd9bb45b36eed62d8b4dc.tar.bz2
fixed normalization for the single-character trailing component
Thanks Hiroyuki ARAKI for spotting the bug and providing the fix Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--lib/util.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/util.cc b/lib/util.cc
index 249eeed..4028697 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -343,65 +343,65 @@ namespace opkele {
}
string::size_type n = interesting;
char tmp[3] = { 0,0,0 };
stack<string::size_type> psegs; psegs.push(rv.length());
string pseg;
for(;n<ul;) {
string::size_type unsafe = uri.find_first_of(qf?"%":"%/?#",n);
if(unsafe==string::npos) {
pseg.append(uri,n,ul-n-1); n = ul-1;
}else{
pseg.append(uri,n,unsafe-n);
n = unsafe;
}
char c = uri[n++];
if(c=='%') {
if((n+1)>=ul)
throw bad_input(OPKELE_CP_ "Unexpected end of URI encountered while parsing percent-encoded character");
tmp[0] = uri[n++];
tmp[1] = uri[n++];
if(!( isxdigit(tmp[0]) && isxdigit(tmp[1]) ))
throw bad_input(OPKELE_CP_ "Invalid percent-encoded character in URI being normalized");
int cc = strtol(tmp,0,16);
if( isalpha(cc) || isdigit(cc) || strchr("._~-",cc) )
pseg += (char)cc;
else{
pseg += '%';
pseg += (char)toupper(tmp[0]); pseg += (char)toupper(tmp[1]);
}
}else if(qf) {
rv += pseg; rv += c;
pseg.clear();
}else if(n>=ul || strchr("?/#",c)) {
- if(pseg.empty() || pseg==".") {
+ if( (unsafe!=string::npos && pseg.empty()) || pseg==".") {
}else if(pseg=="..") {
if(psegs.size()>1) {
rv.resize(psegs.top()); psegs.pop();
}
}else{
psegs.push(rv.length());
if(c!='/') {
pseg += c;
qf = true;
}
rv += '/'; rv += pseg;
}
if(c=='/' && (n>=ul || strchr("?#",uri[n])) ) {
rv += '/';
if(n<ul)
qf = true;
}else if(strchr("?#",c)) {
if(psegs.size()==1 && psegs.top()==rv.length())
rv += '/';
if(pseg.empty())
rv += c;
qf = true;
}
pseg.clear();
}else{
pseg += c;
}
}
if(!pseg.empty()) {
if(!qf) rv += '/';
rv += pseg;
}