aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-06-19 16:46:49 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-06-19 16:47:01 +0100
commit14cf12a2f28dec2a3f7b8b883838f4a801e1a4ce (patch)
treeeb5fee7c17021078cbed65bec26b405f1a7369e7
parent018c963f0ea76a9bdd4f36b31f620ff520e66eb3 (diff)
downloadpaludis-14cf12a2f28dec2a3f7b8b883838f4a801e1a4ce.tar.gz
paludis-14cf12a2f28dec2a3f7b8b883838f4a801e1a4ce.tar.xz
More robust missing EOL handling
-rw-r--r--paludis/util/config_file.cc9
-rw-r--r--paludis/util/config_file_TEST.cc16
2 files changed, 18 insertions, 7 deletions
diff --git a/paludis/util/config_file.cc b/paludis/util/config_file.cc
index c9c5848..d2c4c73 100644
--- a/paludis/util/config_file.cc
+++ b/paludis/util/config_file.cc
@@ -391,9 +391,12 @@ namespace
}
else if ((! k.options()[kvcfo_ignore_single_quotes_inside_strings]) && parser.consume(simple_parser::exact("'")))
break;
- else if ((k.options()[kvcfo_ignore_single_quotes_inside_strings]) &&
- (parser.lookahead(simple_parser::exact("'\n")) || ! parser.lookahead(simple_parser::any_except(""))) &&
- parser.consume(simple_parser::exact("'")))
+ else if ((k.options()[kvcfo_ignore_single_quotes_inside_strings]) && parser.lookahead(simple_parser::exact("'\n"))
+ && parser.consume(simple_parser::exact("'")))
+ break;
+ else if ((k.options()[kvcfo_ignore_single_quotes_inside_strings]) && parser.lookahead(simple_parser::exact("'"))
+ && ! parser.lookahead(simple_parser::exact("'") & simple_parser::any_except(""))
+ && parser.consume(simple_parser::exact("'")))
break;
else if (parser.consume((simple_parser::any_except("") & *simple_parser::any_except("\\'")) >> s))
result.append(s);
diff --git a/paludis/util/config_file_TEST.cc b/paludis/util/config_file_TEST.cc
index ed53efb..be9850f 100644
--- a/paludis/util/config_file_TEST.cc
+++ b/paludis/util/config_file_TEST.cc
@@ -458,12 +458,12 @@ TEST(KeyValueConfigFile, EnvVars)
TEST(KeyValueConfigFile, AnnoyingLibtoolQuotes)
{
std::stringstream s1;
- s1 << "x='foo 'bar' baz'\ny=z" << std::endl;
+ s1 << "x='foo 'bar' baz'\ny=z";
EXPECT_THROW(KeyValueConfigFile ff(s1, { },
&KeyValueConfigFile::no_defaults, &KeyValueConfigFile::no_transformation), ConfigurationError);
std::stringstream s2;
- s2 << "x='foo 'bar' baz'\ny=z" << std::endl;
+ s2 << "x='foo 'bar' baz'\ny=z";
KeyValueConfigFile ff(s2, { kvcfo_ignore_single_quotes_inside_strings },
&KeyValueConfigFile::no_defaults, &KeyValueConfigFile::no_transformation);
@@ -472,11 +472,19 @@ TEST(KeyValueConfigFile, AnnoyingLibtoolQuotes)
EXPECT_EQ("z", ff.get("y"));
std::stringstream s3;
- s3 << "x='foo 'bar' baz'" << std::endl;
+ s3 << "x='foo 'bar' baz'";
KeyValueConfigFile f3(s3, { kvcfo_ignore_single_quotes_inside_strings },
&KeyValueConfigFile::no_defaults, &KeyValueConfigFile::no_transformation);
ASSERT_EQ(1, std::distance(f3.begin(), f3.end()));
- EXPECT_EQ("foo 'bar' baz", ff.get("x"));
+ EXPECT_EQ("foo 'bar' baz", f3.get("x"));
+
+ std::stringstream s4;
+ s4 << "x='foo'";
+ KeyValueConfigFile f4(s4, { kvcfo_ignore_single_quotes_inside_strings },
+ &KeyValueConfigFile::no_defaults, &KeyValueConfigFile::no_transformation);
+
+ ASSERT_EQ(1, std::distance(f4.begin(), f4.end()));
+ EXPECT_EQ("foo", f4.get("x"));
}