summaryrefslogtreecommitdiffstats
path: root/src/manifest_parser_test.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-07-18 00:38:48 (GMT)
committerEvan Martin <martine@danga.com>2012-07-18 00:38:48 (GMT)
commit8a37bfffcbea27ffbb9168b2740476336cd4963a (patch)
tree858b58f1fb26898be995f6540eb03430ad8e2130 /src/manifest_parser_test.cc
parent42163db5edfd6865a05226af23f99aef3622f550 (diff)
downloadNinja-8a37bfffcbea27ffbb9168b2740476336cd4963a.zip
Ninja-8a37bfffcbea27ffbb9168b2740476336cd4963a.tar.gz
Ninja-8a37bfffcbea27ffbb9168b2740476336cd4963a.tar.bz2
disallow crlf in manifest files
It turns out to be trickier than expected to process these correctly. It turns out to also be trickier than expected to give a nice error message on encountering these. But the behavior prior to this patch would just be silent failures where we attempted to examine paths that accidentally contained embedded \r. For now, fix all regexes of the form [^...] to include \r in the excluded block, then assert that we get a vague lexer error near the problem. In the future perhaps we can open manifest files in text mode on Windows or just disallow Windows-style CRLF in the manual.
Diffstat (limited to 'src/manifest_parser_test.cc')
-rw-r--r--src/manifest_parser_test.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/manifest_parser_test.cc b/src/manifest_parser_test.cc
index 9c6644c..3261d39 100644
--- a/src/manifest_parser_test.cc
+++ b/src/manifest_parser_test.cc
@@ -682,3 +682,23 @@ TEST_F(ParserTest, UTF8) {
" command = true\n"
" description = compilaci\xC3\xB3\n"));
}
+
+// We might want to eventually allow CRLF to be nice to Windows developers,
+// but for now just verify we error out with a nice message.
+TEST_F(ParserTest, CRLF) {
+ State state;
+ ManifestParser parser(&state, NULL);
+ string err;
+
+ EXPECT_FALSE(parser.ParseTest("# comment with crlf\r\n",
+ &err));
+ EXPECT_EQ("input:1: lexing error\n",
+ err);
+
+ EXPECT_FALSE(parser.ParseTest("foo = foo\nbar = bar\r\n",
+ &err));
+ EXPECT_EQ("input:2: lexing error\n"
+ "bar = bar\r\n"
+ " ^ near here",
+ err);
+}