diff options
author | Jan Engelhardt <[email protected]> | 2024-03-04 10:46:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2024-03-04 10:46:03 +0000 |
commit | 0ce327abee4666385ebb54a7530e4710b63265a3 (patch) | |
tree | 1715422de3ea4dbd2eea47e877c291fd68154f85 /src | |
parent | url: repair off-by-one bug in extractHost (#297) (diff) | |
download | vmime-0ce327abee4666385ebb54a7530e4710b63265a3.tar.gz vmime-0ce327abee4666385ebb54a7530e4710b63265a3.zip |
url: strip leading slash from url-path (#298)
Diffstat (limited to 'src')
-rw-r--r-- | src/vmime/utility/url.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/vmime/utility/url.cpp b/src/vmime/utility/url.cpp index e8978d28..f0d9c657 100644 --- a/src/vmime/utility/url.cpp +++ b/src/vmime/utility/url.cpp @@ -274,9 +274,20 @@ void url::parse(const string& str) { extractHost(hostPart, host, port); // Path - string path = utility::stringUtils::trim(string(str.begin() + slashPos, str.end())); + string path; string params; + if (slashPos != str.size()) { + + // Cf. RFC 1738 ยง3.1 page 6. For all URLs that follow Common + // Internet Scheme Syntax (and this parser demands it by only + // allowing URLs with "://" above), the separator is not + // actually part of the path. + auto pathStart = slashPos + 1; + path = utility::stringUtils::trim(string(str.begin() + pathStart, str.end())); + + } + size_t paramSep = path.find_first_of('?'); if (paramSep != string::npos) { @@ -285,10 +296,6 @@ void url::parse(const string& str) { path.erase(path.begin() + paramSep, path.end()); } - if (path == "/") { - path.clear(); - } - // Some sanity check if (proto.empty()) { |