From 1f85f6dee187e98ff88193af2c2542af3ceb5717 Mon Sep 17 00:00:00 2001 From: Sanket Patel Date: Fri, 4 Dec 2026 08:57:49 +0000 Subject: [PATCH 1/2] test(engine): cover OS qualifier parsing --- .../server/engine-core/test/match/Glob.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/server/engine-core/test/match/Glob.cpp b/packages/server/engine-core/test/match/Glob.cpp index d1f6b8371e..edb5ba8edd 100644 --- a/packages/server/engine-core/test/match/Glob.cpp +++ b/packages/server/engine-core/test/match/Glob.cpp @@ -141,6 +141,32 @@ TEST_CASE("Glob match tests") { REQUIRE(glob.matches("john")); } + SECTION("OS qualifier parsing") { + Text matchStr = "/home/*"; + auto result = globber::parseAndRemoveOsQualifier(matchStr); + REQUIRE(result); + REQUIRE(result.value() == plat::Type::Linux); + REQUIRE(matchStr == "/home/*"); + } + + SECTION("Unclosed OS qualifier is not parsed") { + auto checkUnclosedQualifier = [](Text pattern) { + const auto original = pattern; + auto result = globber::parseAndRemoveOsQualifier(pattern); + REQUIRE(!result); + REQUIRE(pattern == original); + + globber::Glob matcher; + REQUIRE(!globber::createPathMatcher(pattern, 0, matcher)); + REQUIRE(matcher.pattern() == original); + }; + + checkUnclosedQualifier("<*"); + checkUnclosedQualifier(" Date: Fri, 4 Dec 2026 09:00:46 +0000 Subject: [PATCH 2/2] fix(engine): reject unclosed OS qualifier in include/exclude paths --- packages/server/engine-core/apLib/match/api.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/server/engine-core/apLib/match/api.cpp b/packages/server/engine-core/apLib/match/api.cpp index a4d1773e6d..fb245aee74 100644 --- a/packages/server/engine-core/apLib/match/api.cpp +++ b/packages/server/engine-core/apLib/match/api.cpp @@ -33,16 +33,11 @@ namespace ap::globber { // extract this and match it against an os name, while also // pruning the callers string Opt parseAndRemoveOsQualifier(Text &pattern) noexcept { - // Extract the first instance of a <> - auto comps = string::split(pattern, ">", false, 1); - - // No comps, no os prefix - if (comps.empty()) return {}; - - // Got some comps, first component has the os if it leads with - // a <, if so grab the os prefix at position 1 - if (!comps[0].startsWith("<")) return {}; - auto osPrefix = comps[0].substr(1); + // An OS qualifier only exists when a leading < is closed + if (!pattern.startsWith("<")) return {}; + auto qualifierEnd = pattern.find('>'); + if (qualifierEnd == Text::npos) return {}; + auto osPrefix = pattern.substr(1, qualifierEnd - 1); // Now wildcards are used here to use glob to match it auto osMatch = Glob(osPrefix, 0); @@ -62,7 +57,7 @@ Opt parseAndRemoveOsQualifier(Text &pattern) noexcept { // If we found one, remove the leading portion from the callers // string - if (osType) pattern = pattern.substr(osMatch.pattern().size() + 2); + if (osType) pattern = pattern.substr(qualifierEnd + 1); return osType; }