From 0ce327abee4666385ebb54a7530e4710b63265a3 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Mon, 4 Mar 2024 11:46:03 +0100 Subject: url: strip leading slash from url-path (#298) --- src/vmime/utility/url.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') 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()) { -- cgit v1.2.3