Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vcpkg-test/platform-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ TEST_CASE ("missing closing )", "[platform-expression]")
{
CHECK_FALSE(parse_expr("(windows & arm | linux"));
CHECK_FALSE(parse_expr("( (windows & arm) | (osx & arm64) | linux"));
CHECK_FALSE(parse_expr("(!((windows & x64 & !uwp) & !(linux & x64))"));
}

TEST_CASE ("missing or invalid identifier", "[platform-expression]")
Expand Down
72 changes: 72 additions & 0 deletions src/vcpkg-test/specifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,76 @@ TEST_CASE ("specifier parsing", "[specifier]")
on expression: zlib (windows)
^)"));
}

SECTION ("parsed specifier from string with unclosed empty qualifier")
{
auto s = vcpkg::parse_qualified_specifier(
"zlib(", AllowFeatures::Yes, ParseExplicitTriplet::Allow, AllowPlatformSpec::Yes);
if (s.has_value())
{
FAIL();
}
else
{
REQUIRE(s.error() == LocalizedString::from_raw(
R"(error: missing closing )
on expression: zlib(
^)"));
}
}

SECTION ("parsed specifier from string with unclosed empty qualifier newline")
{
auto s = vcpkg::parse_qualified_specifier(
"zlib(\n", AllowFeatures::Yes, ParseExplicitTriplet::Allow, AllowPlatformSpec::Yes);
if (s.has_value())
{
FAIL();
}
else
{
REQUIRE(s.error() == LocalizedString::from_raw(
R"(error: missing closing )
on expression: zlib(
^)"));
}
}

SECTION ("parsed specifier from string with unclosed qualifier")
{
auto s = vcpkg::parse_qualified_specifier("zlib:x64-windows(!((windows & x64 & !uwp) & !(linux & x64))",
AllowFeatures::Yes,
ParseExplicitTriplet::Allow,
AllowPlatformSpec::Yes);
if (s.has_value())
{
FAIL();
}
else
{
REQUIRE(s.error() == LocalizedString::from_raw(
R"(error: missing closing )
on expression: zlib:x64-windows(!((windows & x64 & !uwp) & !(linux & x64))
^)"));
}
}

SECTION ("parsed specifier from string with unclosed qualifier newline")
{
auto s = vcpkg::parse_qualified_specifier("zlib:x64-windows(!((windows & x64 & !uwp) & !(linux & x64))\n",
AllowFeatures::Yes,
ParseExplicitTriplet::Allow,
AllowPlatformSpec::Yes);
if (s.has_value())
{
FAIL();
}
else
{
REQUIRE(s.error() == LocalizedString::from_raw(
R"(error: missing closing )
on expression: zlib:x64-windows(!((windows & x64 & !uwp) & !(linux & x64))
^)"));
}
}
}
47 changes: 33 additions & 14 deletions src/vcpkg/packagespec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,32 +376,51 @@ namespace vcpkg
return nullopt;
}

auto loc = parser.cur_loc();
std::string platform_string;
int depth = 1;
while (depth > 0 && (ch = parser.next()) != 0)
ch = parser.next();
if (ch == '\r' || ch == '\n' || ch == Unicode::end_of_file)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a behavior change to no longer accept newlines but ~every real use case here already won't practically allow newlines and this makes the diagnostics better.

{
if (ch == '(') ++depth;
if (ch == ')') --depth;
parser.add_error(msg::format(msgMissingClosingParen));
return nullopt;
}
if (depth > 0)

auto expr_loc = parser.cur_loc();
int depth = 1;
for (;;)
{
parser.add_error(msg::format(msgMissingClosingParen), loc);
return nullopt;
if (ch == '(')
{
++depth;
}
else if (ch == ')')
{
--depth;
if (depth == 0)
{
break;
}
}

ch = parser.next();
if (ch == '\r' || ch == '\n' || ch == Unicode::end_of_file)
{
parser.add_error(msg::format(msgMissingClosingParen));
return nullopt;
}
}
platform_string.append((++loc.it).pointer_to_current(), parser.it().pointer_to_current());

auto platform_opt = PlatformExpression::parse_platform_expression(
platform_string, PlatformExpression::MultipleBinaryOperators::Allow);
std::string(expr_loc.it.pointer_to_current(), parser.it().pointer_to_current()),
PlatformExpression::MultipleBinaryOperators::Allow);
if (auto platform = platform_opt.get())
{
ret.platform.emplace(loc, std::move(*platform));
ret.platform.emplace(expr_loc, std::move(*platform));
}
else
{
parser.add_error(std::move(platform_opt).error(), loc);
parser.add_error(std::move(platform_opt).error(), expr_loc);
}

parser.next();
parser.next(); // consume ')'
}
// This makes the behavior of the parser more consistent -- otherwise, it will skip tabs and spaces only if
// there isn't a qualifier.
Expand Down
Loading