|
Boost-Commit : |
From: daniel_james_at_[hidden]
Date: 2008-02-10 14:41:51
Author: danieljames
Date: 2008-02-10 14:41:50 EST (Sun, 10 Feb 2008)
New Revision: 43217
URL: http://svn.boost.org/trac/boost/changeset/43217
Log:
Decode any html encoded ampersands in the URL.
Text files modified:
branches/fix-links/tools/inspect/link_check.cpp | 35 +++++++++++++++++++++++++----------
1 files changed, 25 insertions(+), 10 deletions(-)
Modified: branches/fix-links/tools/inspect/link_check.cpp
==============================================================================
--- branches/fix-links/tools/inspect/link_check.cpp (original)
+++ branches/fix-links/tools/inspect/link_check.cpp 2008-02-10 14:41:50 EST (Sun, 10 Feb 2008)
@@ -20,22 +20,37 @@
"\\s*=\\s*(['\"])(.*?)\\1",
boost::regbase::normal | boost::regbase::icase);
- // Decode percent encoded characters, returns an empty string if there's an
- // error.
+ // Decode percent encoded characters and html escapsed ampersands,
+ // returns an empty string if there's an error.
+ // The urls should really be fully HTML decoded at the beginning.
std::string decode_url(std::string const& path) {
std::string::size_type pos = 0, next;
std::string result;
result.reserve(path.length());
- while((next = path.find('%', pos)) != std::string::npos) {
+ while((next = path.find_first_of("&%", pos)) != std::string::npos) {
result.append(path, pos, next - pos);
-
- if(path.length() - next < 3) return "";
- char hex[3] = { path[next + 1], path[next + 2], '\0' };
- char* end_ptr;
- result += (char) std::strtol(hex, &end_ptr, 16);
- if(*end_ptr) return "";
- pos = next + 3;
+ pos = next;
+ switch(path[pos]) {
+ case '%': {
+ if(path.length() - next < 3) return "";
+ char hex[3] = { path[next + 1], path[next + 2], '\0' };
+ char* end_ptr;
+ result += (char) std::strtol(hex, &end_ptr, 16);
+ if(*end_ptr) return "";
+ pos = next + 3;
+ break;
+ }
+ case '&': {
+ if(path.substr(pos, 5) == "&") {
+ result += '&'; pos += 5;
+ }
+ else {
+ result += '&'; pos += 1;
+ }
+ break;
+ }
+ }
}
result.append(path, pos, path.length());
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk