From 5b80b067e7cd5d25be09641e228f0a08534c6a03 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 30 Nov 2016 16:47:16 +0300 Subject: Adapt to semantics change of path::normalize() --- bpkg/manifest.cxx | 10 +++++----- tests/repository-location/driver.cxx | 29 ++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/bpkg/manifest.cxx b/bpkg/manifest.cxx index 246251d..5569224 100644 --- a/bpkg/manifest.cxx +++ b/bpkg/manifest.cxx @@ -1675,9 +1675,8 @@ namespace bpkg } // Need to check path for emptiness before proceeding further as a valid - // non empty location can not have an empty path_ member. Note that path - // can become empty as a result of normalize () call. Example of such a - // path is 'a/..'. + // non empty location can not have an empty path_ member (which can be the + // case for the remote location, but not for the relative or absolute). // if (path_.empty ()) throw invalid_argument ("empty path"); @@ -2017,13 +2016,14 @@ namespace bpkg // dir_path ipath ( strip_path ( - u.path, strip_p ? strip_mode::component : strip_mode::version) / rpath); + u.path, + strip_p ? strip_mode::component : strip_mode::version) / rpath); static const char* invalid_location ("invalid repository location"); try { - ipath.normalize (); + ipath.normalize (false, true); // Current dir collapses to an empty one. } catch (const invalid_path&) { diff --git a/tests/repository-location/driver.cxx b/tests/repository-location/driver.cxx index 441e295..6b4a1d7 100644 --- a/tests/repository-location/driver.cxx +++ b/tests/repository-location/driver.cxx @@ -133,7 +133,6 @@ main (int argc, char* argv[]) assert (bad_location ("1/..")); assert (bad_location ("bbb")); assert (bad_location ("aaa/bbb")); - assert (bad_location ("/aaa/bbb")); assert (bad_location ("http://aa")); assert (bad_location ("https://aa")); assert (bad_location ("http://aa/")); @@ -143,6 +142,12 @@ main (int argc, char* argv[]) assert (bad_location ("http://a.com/../c/1/aa")); assert (bad_location ("http://a.com/a/b/../../../c/1/aa")); +#ifndef _WIN32 + assert (bad_location ("/aaa/bbb")); +#else + assert (bad_location ("c:\\aaa\\bbb")); +#endif + // Invalid version. // assert (bad_location ("3/aaa/bbb")); @@ -159,6 +164,11 @@ main (int argc, char* argv[]) repository_location ( "http://stable.cppget.org/1/misc"))); + + assert (bad_location ("../..", + repository_location ( + "http://stable.cppget.org/1/misc"))); + // Invalid web interface URL. // assert (bad_url (".a/..", @@ -225,6 +235,11 @@ main (int argc, char* argv[]) assert (l.string () == "b/pkg/1/aa/bb"); assert (l.canonical_name ().empty ()); } + { + repository_location l ("aa/..", repository_location ()); + assert (l.string () == "."); + assert (l.canonical_name ().empty ()); + } #ifndef _WIN32 { repository_location l ("/1/aa/bb", repository_location ()); @@ -427,6 +442,18 @@ main (int argc, char* argv[]) assert (l2.canonical_name () == "stable.cppget.org/math"); } { + repository_location l1 ("http://stable.cppget.org/1/misc"); + repository_location l2 ("math/..", l1); + assert (l2.string () == "http://stable.cppget.org/1/misc"); + assert (l2.canonical_name () == "stable.cppget.org/misc"); + } + { + repository_location l1 ("http://stable.cppget.org/1/misc"); + repository_location l2 (".", l1); + assert (l2.string () == "http://stable.cppget.org/1/misc"); + assert (l2.canonical_name () == "stable.cppget.org/misc"); + } + { repository_location l1 ("http://www.stable.cppget.org:8080/1"); repository_location l2 ("../1/math", l1); assert (l2.string () == "http://www.stable.cppget.org:8080/1/math"); -- cgit v1.1