Skip to content
Open
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
17 changes: 6 additions & 11 deletions packages/server/engine-core/apLib/match/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@ namespace ap::globber {
// extract this and match it against an os name, while also
// pruning the callers string
Opt<plat::Type> 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);
Expand All @@ -62,7 +57,7 @@ Opt<plat::Type> 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;
}
Expand Down
26 changes: 26 additions & 0 deletions packages/server/engine-core/test/match/Glob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,32 @@ TEST_CASE("Glob match tests") {
REQUIRE(glob.matches("john"));
}

SECTION("OS qualifier parsing") {
Text matchStr = "<Linux*>/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("<Linux");
checkUnclosedQualifier("<Mac");
checkUnclosedQualifier("<");
}

#if ROCKETRIDE_PLAT_WIN
SECTION("Windows") {
SECTION("Os prefix parsing") {
Expand Down