From 503a9591c95ae986f42426f69ce3d003011f4162 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 21 Oct 2020 12:35:21 +0200 Subject: [PATCH] URL parser bugfix --- lib/url.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/url.cpp b/lib/url.cpp index 785c1821..1474dd48 100644 --- a/lib/url.cpp +++ b/lib/url.cpp @@ -74,6 +74,19 @@ HTTP::URL::URL(const std::string &url){ } if (path.substr(0, 2) == "./"){path.erase(0, 2);} if (path.substr(0, 3) == "../"){path.erase(0, 3);} + //RFC 2396 sec 5.2: check if URL ends with /.. -> remove iff name != .. + if (path.length() == 2 && path == "..") + path = ""; + if (path.length() > 2 && path.substr(path.length() - 2) == ".."){ + // || == 1, so != '..' + if (path.length() == 4){ + path.erase(path.length() - 4, path.length()); + } + else if (path.length() > 4 && path.substr(path.length() - 5) != "../.."){ + size_t prevslash = path.rfind('/', path.length() - 4); + path.erase(prevslash + 1, path.length()); + } + } path = Encodings::URL::decode(path); } }