Merge pull request #947 from KLayout/issue-946

Fixed issue #946 for the case of file paths with blanks
This commit is contained in:
Matthias Köfferlein 2021-12-16 07:55:58 +01:00 committed by GitHub
commit 7bc5b51fad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 2 deletions

View File

@ -134,7 +134,11 @@ IncludeExpander::to_string () const
tl_assert (m_sections.begin ()->second.second == 0);
std::string fn = m_sections.begin ()->second.first;
return tl::to_word_or_quoted_string (fn, valid_fn_chars);
if (! fn.empty () && fn.front () == '@') {
return tl::to_quoted_string (fn);
} else {
return fn;
}
} else {
@ -166,7 +170,9 @@ IncludeExpander::from_string (const std::string &s)
ex.read_quoted (ie.m_sections [1].first);
} else if (ex.test ("@")) {
} else if (*ex == '@') {
++ex;
while (! ex.at_end ()) {

View File

@ -108,3 +108,31 @@ TEST(4_multi_include_interpolate)
EXPECT_EQ (ie.translate_to_original (6).second, 3);
}
TEST(5_issue946)
{
std::string fn = tl::testdata () + "/tl/x_inc4.txt";
std::string et;
tl::IncludeExpander ie = tl::IncludeExpander::expand (fn, tl::InputStream (fn).read_all (), et);
EXPECT_EQ (et, "A line\nincluded.4\nAnother line\n");
EXPECT_EQ (np (ie.to_string ()), np ("@1*" + tl::testdata () + "/tl/x_inc4.txt*0;2*'" + tl::testdata () + "/tl/inc 4.txt'*-1;3*" + tl::testdata () + "/tl/x_inc4.txt*0;"));
EXPECT_EQ (tl::IncludeExpander::from_string (ie.to_string ()).to_string (), ie.to_string ());
EXPECT_EQ (ie.translate_to_original (1).first, fn);
EXPECT_EQ (ie.translate_to_original (1).second, 1);
EXPECT_EQ (np (ie.translate_to_original (2).first), np (tl::testdata () + "/tl/inc 4.txt"));
EXPECT_EQ (ie.translate_to_original (2).second, 1);
EXPECT_EQ (ie.translate_to_original (3).first, fn);
EXPECT_EQ (ie.translate_to_original (3).second, 3);
fn = tl::testdata () + "/tl/inc 4.txt";
et.clear ();
ie = tl::IncludeExpander::expand (fn, tl::InputStream (fn).read_all (), et);
EXPECT_EQ (et, "included.4\n");
// no quotes here so this string can be used as the original file name if there is no include
EXPECT_EQ (np (ie.to_string ()), np (tl::testdata () + "/tl/inc 4.txt"));
}

1
testdata/tl/inc 4.txt vendored Normal file
View File

@ -0,0 +1 @@
included.4

3
testdata/tl/x_inc4.txt vendored Normal file
View File

@ -0,0 +1,3 @@
A line
# %include 'inc 4.txt'
Another line