mirror of https://github.com/KLayout/klayout.git
Magic file writer fixes for Windows - file path handling wasn't right for windows paths with drives.
This commit is contained in:
parent
76c9d00ed2
commit
76c42f2959
|
|
@ -100,7 +100,9 @@ URI::URI (const std::string &uri)
|
||||||
tl::Extractor ex0 (uri.c_str ());
|
tl::Extractor ex0 (uri.c_str ());
|
||||||
tl::Extractor ex = ex0;
|
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
|
// got scheme
|
||||||
++ex;
|
++ex;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,15 @@
|
||||||
|
|
||||||
#include "tlUri.h"
|
#include "tlUri.h"
|
||||||
#include "tlUnitTest.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)
|
std::string uri2string (const tl::URI &uri)
|
||||||
{
|
{
|
||||||
|
|
@ -142,3 +151,28 @@ TEST(1)
|
||||||
EXPECT_EQ (uri2string (uri), "</path/to/file>?<a>=<v1>&<b>=<v2>&<c>=<v3>#<fragment>");
|
EXPECT_EQ (uri2string (uri), "</path/to/file>?<a>=<v1>&<b>=<v2>&<c>=<v3>#<fragment>");
|
||||||
EXPECT_EQ (uri2string (uri.resolved (tl::URI ("../other"))), "</path/to/file/../other>");
|
EXPECT_EQ (uri2string (uri.resolved (tl::URI ("../other"))), "</path/to/file/../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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,7 +28,6 @@ SOURCES = \
|
||||||
tlUtils.cc \
|
tlUtils.cc \
|
||||||
tlVariant.cc \
|
tlVariant.cc \
|
||||||
tlXMLParser.cc \
|
tlXMLParser.cc \
|
||||||
tlUri.cc \
|
|
||||||
tlStreamTests.cc \
|
tlStreamTests.cc \
|
||||||
tlWebDAV.cc \
|
tlWebDAV.cc \
|
||||||
tlHttpStream.cc \
|
tlHttpStream.cc \
|
||||||
|
|
@ -39,7 +38,8 @@ SOURCES = \
|
||||||
tlEquivalenceClustersTests.cc \
|
tlEquivalenceClustersTests.cc \
|
||||||
tlUniqueNameTests.cc \
|
tlUniqueNameTests.cc \
|
||||||
tlGlobPatternTests.cc \
|
tlGlobPatternTests.cc \
|
||||||
tlRecipeTests.cc
|
tlRecipeTests.cc \
|
||||||
|
tlUriTests.cc
|
||||||
|
|
||||||
!equals(HAVE_QT, "0") {
|
!equals(HAVE_QT, "0") {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue