Make URL decoding even more solid.
* Thanks to korli for pointing remaining issues.
This commit is contained in:
@@ -1005,23 +1005,22 @@ BUrl::_DoUrlDecodeChunk(const BString& chunk, bool strict)
|
|||||||
if (chunk[i] == '+' && !strict)
|
if (chunk[i] == '+' && !strict)
|
||||||
result << ' ';
|
result << ' ';
|
||||||
else {
|
else {
|
||||||
bool isEncoded = false;
|
|
||||||
char decoded = 0;
|
char decoded = 0;
|
||||||
|
char* out = NULL;
|
||||||
|
char hexString[3];
|
||||||
|
|
||||||
if (chunk[i] == '%' && i < chunk.Length() - 2)
|
if (chunk[i] == '%' && i < chunk.Length() - 2
|
||||||
{
|
&& isxdigit(chunk[i + 1]) && isxdigit(chunk[i+2])) {
|
||||||
char hexString[] = { chunk[i + 1], chunk[i + 2], 0 };
|
hexString[0] = chunk[i + 1];
|
||||||
char* out = NULL;
|
hexString[1] = chunk[i + 2];
|
||||||
|
hexString[2] = 0;
|
||||||
decoded = (char)strtol(hexString, &out, 16);
|
decoded = (char)strtol(hexString, &out, 16);
|
||||||
if (out == hexString + 2) {
|
|
||||||
isEncoded = true;
|
|
||||||
i += 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEncoded)
|
if (out == hexString + 2) {
|
||||||
|
i += 2;
|
||||||
result << decoded;
|
result << decoded;
|
||||||
else
|
} else
|
||||||
result << chunk[i];
|
result << chunk[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user