From e7b033d7b38bc55f934521b5f35060b43a8b0526 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 30 Nov 2016 11:47:27 +0300 Subject: Make path::normalize() to preserve ./, invalidate paths starting with \, / on Windows --- butl/path.txx | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'butl/path.txx') diff --git a/butl/path.txx b/butl/path.txx index 5bcaea0..0cdaf5b 100644 --- a/butl/path.txx +++ b/butl/path.txx @@ -147,7 +147,7 @@ namespace butl template basic_path& basic_path:: - normalize (bool actual) + normalize (bool actual, bool cur_empty) { if (empty ()) return *this; @@ -273,12 +273,24 @@ namespace butl p += traits::directory_separator; } - if (tsep && (!p.empty () || abs)) // Distinguish "/"-empty and "."-empty. + if (tsep) { if (p.empty ()) { - p += traits::directory_separator; - ts = -1; + // Distinguish "/"-empty and "."-empty. + // + if (abs) + { + p += traits::directory_separator; + ts = -1; + } + else if (!cur_empty) // Collapse to canonical current directory. + { + p = "."; + ts = 1; // Canonical separator is always first. + } + else // Collapse to empty path. + ts = 0; } else ts = 1; // Canonical separator is always first. @@ -313,11 +325,11 @@ namespace butl #ifdef _WIN32 // We do not support any special Windows path name notations like in C:abc, - // \\?\c:\abc, \\server\abc and \\?\UNC\server\abc (more about them at - // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx). + // /, \, /abc, \abc, \\?\c:\abc, \\server\abc and \\?\UNC\server\abc (more + // about them in "Naming Files, Paths, and Namespaces" MSDN article). // if ((n > 2 && s[1] == ':' && s[2] != '\\' && s[2] != '/') || - (n > 1 && s[0] == '\\' && s[1] == '\\')) + (n > 0 && (s[0] == '\\' || s[0] == '/'))) { if (exact) return data_type (); -- cgit v1.1