From c46f3cbd7f9706437392dcfa9df27341aadb1b37 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Mon, 28 Nov 2011 13:54:35 +1100 Subject: When expanding $in and $out, wrap with quotes if the filename has a space. --- src/graph.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/graph.cc b/src/graph.cc index 9f7fc76..ed7097b 100644 --- a/src/graph.cc +++ b/src/graph.cc @@ -189,7 +189,14 @@ string EdgeEnv::MakePathList(vector::iterator begin, for (vector::iterator i = begin; i != end; ++i) { if (!result.empty()) result.push_back(' '); - result.append((*i)->path()); + const string& path = (*i)->path(); + if (path.find(" ") != string::npos) { + result.append("\""); + result.append(path); + result.append("\""); + } else { + result.append(path); + } } return result; } -- cgit v0.12 From c74e70c2d865be8fc19affb390ea0704fa3eea50 Mon Sep 17 00:00:00 2001 From: Jeremy Apthorp Date: Thu, 5 Jan 2012 10:00:24 +1100 Subject: Add a test for quoting spaces in expanded $in and $out. --- src/graph_test.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/graph_test.cc b/src/graph_test.cc index c1a0f93..07a1936 100644 --- a/src/graph_test.cc +++ b/src/graph_test.cc @@ -131,3 +131,12 @@ TEST_F(GraphTest, RootNodes) { EXPECT_EQ("out", name.substr(0, 3)); } } + +TEST_F(GraphTest, VarInOutQuoteSpaces) { + ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, +"build a$ b: cat nospace with$ space nospace2\n")); + + Edge* edge = GetNode("a b")->in_edge(); + EXPECT_EQ("cat nospace \"with space\" nospace2 > \"a b\"", + edge->EvaluateCommand()); +} -- cgit v0.12