Implement LWG 3096: path::lexically_relative is confused by trailing slashes
path("/dir/").lexically_relative("/dir"); now returns "." instead of ""
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@349885 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1478,7 +1478,7 @@ static int DetermineLexicalElementCount(PathParser PP) {
|
||||
auto Elem = *PP;
|
||||
if (Elem == "..")
|
||||
--Count;
|
||||
else if (Elem != ".")
|
||||
else if (Elem != "." && Elem != "")
|
||||
++Count;
|
||||
}
|
||||
return Count;
|
||||
@@ -1492,8 +1492,7 @@ path path::lexically_relative(const path& base) const {
|
||||
return PP.State != PPBase.State &&
|
||||
(PP.inRootPath() || PPBase.inRootPath());
|
||||
};
|
||||
if (PP.State == PathParser::PS_InRootName &&
|
||||
PPBase.State == PathParser::PS_InRootName) {
|
||||
if (PP.inRootName() && PPBase.inRootName()) {
|
||||
if (*PP != *PPBase)
|
||||
return {};
|
||||
} else if (CheckIterMismatchAtBase())
|
||||
@@ -1525,6 +1524,10 @@ path path::lexically_relative(const path& base) const {
|
||||
if (ElemCount < 0)
|
||||
return {};
|
||||
|
||||
// if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
|
||||
if (ElemCount == 0 && (PP.atEnd() || *PP == ""))
|
||||
return ".";
|
||||
|
||||
// return a path constructed with 'n' dot-dot elements, followed by the the
|
||||
// elements of '*this' after the mismatch.
|
||||
path Result;
|
||||
|
||||
@@ -40,8 +40,8 @@ int main() {
|
||||
{"a", "/", ""},
|
||||
{"//net", "a", ""},
|
||||
{"a", "//net", ""},
|
||||
{"//net/", "//net", ""},
|
||||
{"//net", "//net/", ".."},
|
||||
{"//net/", "//net", "."},
|
||||
{"//net", "//net/", "."},
|
||||
{"//base", "a", ""},
|
||||
{"a", "a", "."},
|
||||
{"a/b", "a/b", "."},
|
||||
|
||||
@@ -271,7 +271,7 @@
|
||||
<tr><td><a href="https://wg21.link/LWG3038">3038</a></td><td><tt>polymorphic_allocator::allocate</tt> should not allow integer overflow to create vulnerabilities</td><td>San Diego</td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3054">3054</a></td><td><tt>uninitialized_copy</tt> appears to not be able to meet its exception-safety guarantee</td><td>San Diego</td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3065">3065</a></td><td>LWG 2989 missed that all <tt>path</tt>'s other operators should be hidden friends as well</td><td>San Diego</td><td>Complete</td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3096">3096</a></td><td><tt>path::lexically_relative</tt> is confused by trailing slashes</td><td>San Diego</td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3096">3096</a></td><td><tt>path::lexically_relative</tt> is confused by trailing slashes</td><td>San Diego</td><td>Complete</td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3116">3116</a></td><td><tt><i>OUTERMOST_ALLOC_TRAITS</i></tt> needs <tt>remove_reference_t</tt></td><td>San Diego</td><td></td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3122">3122</a></td><td><tt>__cpp_lib_chrono_udls</tt> was accidentally dropped</td><td>San Diego</td><td><i>We've already made the update; but we don't support all the test macros. When we do, this will be closed</i></td></tr>
|
||||
<tr><td><a href="https://wg21.link/LWG3127">3127</a></td><td><tt>basic_osyncstream::rdbuf</tt> needs a <tt>const_cast</tt></td><td>San Diego</td><td></td></tr>
|
||||
|
||||
Reference in New Issue
Block a user