From 95cfd50d25bf8f5f969bc1fbdc5fd0b967db670b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Jan 2023 14:14:29 +0100 Subject: OutputSpec: Allow all valid output names Fixes #7624. --- src/libstore/outputs-spec.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/libstore/outputs-spec.cc b/src/libstore/outputs-spec.cc index a9e4320d5..096443cb2 100644 --- a/src/libstore/outputs-spec.cc +++ b/src/libstore/outputs-spec.cc @@ -21,7 +21,8 @@ bool OutputsSpec::contains(const std::string & outputName) const std::optional OutputsSpec::parseOpt(std::string_view s) { - static std::regex regex(R"((\*)|([a-z]+(,[a-z]+)*))"); + // See checkName() for valid output name characters. + static std::regex regex(R"((\*)|([a-zA-Z\+\-\._\?=]+(,[a-zA-Z\+\-\._\?=]+)*))"); std::smatch match; std::string s2 { s }; // until some improves std::regex @@ -42,7 +43,7 @@ OutputsSpec OutputsSpec::parse(std::string_view s) { std::optional spec = parseOpt(s); if (!spec) - throw Error("Invalid outputs specifier: '%s'", s); + throw Error("invalid outputs specifier '%s'", s); return *spec; } @@ -65,7 +66,7 @@ std::pair ExtendedOutputsSpec::parse(std: { std::optional spec = parseOpt(s); if (!spec) - throw Error("Invalid extended outputs specifier: '%s'", s); + throw Error("invalid extended outputs specifier '%s'", s); return *spec; } -- cgit v1.2.3 From 75c89c3e5ea4b4b6a47a3c13aec8b3ac5c324fa5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Jan 2023 16:34:37 +0100 Subject: Add test for OutputsSpec::Names From @Ericson2314. --- src/libstore/tests/outputs-spec.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/libstore/tests/outputs-spec.cc b/src/libstore/tests/outputs-spec.cc index c9c2cafd0..836ba7e82 100644 --- a/src/libstore/tests/outputs-spec.cc +++ b/src/libstore/tests/outputs-spec.cc @@ -40,6 +40,13 @@ TEST(OutputsSpec, names_out) { ASSERT_EQ(expected.to_string(), str); } +TEST(OutputsSpec, names_underscore) { + std::string_view str = "a_b"; + OutputsSpec expected = OutputsSpec::Names { "a_b" }; + ASSERT_EQ(OutputsSpec::parse(str), expected); + ASSERT_EQ(expected.to_string(), str); +} + TEST(OutputsSpec, names_out_bin) { OutputsSpec expected = OutputsSpec::Names { "out", "bin" }; ASSERT_EQ(OutputsSpec::parse("out,bin"), expected); -- cgit v1.2.3