diff --git a/src/tl/tl/tlUri.cc b/src/tl/tl/tlUri.cc index 4325f6740..a7c9113d6 100644 --- a/src/tl/tl/tlUri.cc +++ b/src/tl/tl/tlUri.cc @@ -100,7 +100,9 @@ URI::URI (const std::string &uri) tl::Extractor ex0 (uri.c_str ()); tl::Extractor ex = ex0; - if (ex.try_read_word (m_scheme) && *ex == ':') { + // NOTE: to distinguish a windows drive letter from a scheme, we expect the scheme to + // be longer than one character + if (ex.try_read_word (m_scheme) && *ex == ':' && m_scheme.length () > 1) { // got scheme ++ex; } else { diff --git a/src/tl/unit_tests/tlUri.cc b/src/tl/unit_tests/tlUriTests.cc similarity index 88% rename from src/tl/unit_tests/tlUri.cc rename to src/tl/unit_tests/tlUriTests.cc index 1ecdd82d6..0f848fa33 100644 --- a/src/tl/unit_tests/tlUri.cc +++ b/src/tl/unit_tests/tlUriTests.cc @@ -22,6 +22,15 @@ #include "tlUri.h" #include "tlUnitTest.h" +#include "tlFileUtils.h" + +// Secret mode switchers for testing +namespace tl +{ +TL_PUBLIC void file_utils_force_windows (); +TL_PUBLIC void file_utils_force_linux (); +TL_PUBLIC void file_utils_force_reset (); +} std::string uri2string (const tl::URI &uri) { @@ -142,3 +151,28 @@ TEST(1) EXPECT_EQ (uri2string (uri), "?=&=&=#"); EXPECT_EQ (uri2string (uri.resolved (tl::URI ("../other"))), ""); } + +// windows file paths compatibility +TEST(2) +{ + try { + + tl::file_utils_force_windows (); + + // use case taken from Magic writer: + + tl::URI uri ("c:\\users\\myself\\path.txt"); + + std::string ext = tl::extension (uri.path ()); + EXPECT_EQ (ext, "txt"); + + uri.set_path (tl::dirname (uri.path ())); + EXPECT_EQ (uri.to_string (), "C:\\users\\myself"); + + tl::file_utils_force_reset (); + + } catch (...) { + tl::file_utils_force_reset (); + throw; + } +} diff --git a/src/tl/unit_tests/unit_tests.pro b/src/tl/unit_tests/unit_tests.pro index 989902872..ac708a150 100644 --- a/src/tl/unit_tests/unit_tests.pro +++ b/src/tl/unit_tests/unit_tests.pro @@ -28,7 +28,6 @@ SOURCES = \ tlUtils.cc \ tlVariant.cc \ tlXMLParser.cc \ - tlUri.cc \ tlStreamTests.cc \ tlWebDAV.cc \ tlHttpStream.cc \ @@ -39,7 +38,8 @@ SOURCES = \ tlEquivalenceClustersTests.cc \ tlUniqueNameTests.cc \ tlGlobPatternTests.cc \ - tlRecipeTests.cc + tlRecipeTests.cc \ + tlUriTests.cc !equals(HAVE_QT, "0") {