1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14239 from NixOS/asan-stack-overflow

libstore/outputs-spec: Drop usage of std::regex
This commit is contained in:
John Ericson 2025-10-13 21:44:49 +00:00 committed by GitHub
commit 6642ffb506
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,10 +1,10 @@
#include <regex>
#include <nlohmann/json.hpp>
#include <string_view>
#include "nix/store/path.hh"
#include "nix/store/store-dir-config.hh"
#include "nix/util/util.hh"
#include "nix/util/regex-combinators.hh"
#include "nix/store/outputs-spec.hh"
#include "nix/store/path-regex.hh"
#include "nix/util/strings-inline.hh"
namespace nix {
@ -19,31 +19,27 @@ bool OutputsSpec::contains(const std::string & outputName) const
raw);
}
static std::string outputSpecRegexStr = regex::either(regex::group(R"(\*)"), regex::group(regex::list(nameRegexStr)));
std::optional<OutputsSpec> OutputsSpec::parseOpt(std::string_view s)
{
static std::regex regex(std::string{outputSpecRegexStr});
std::cmatch match;
if (!std::regex_match(s.cbegin(), s.cend(), match, regex))
try {
return parse(s);
} catch (BadStorePathName &) {
return std::nullopt;
if (match[1].matched)
return {OutputsSpec::All{}};
if (match[2].matched)
return OutputsSpec::Names{tokenizeString<StringSet>({match[2].first, match[2].second}, ",")};
assert(false);
}
}
OutputsSpec OutputsSpec::parse(std::string_view s)
{
std::optional spec = parseOpt(s);
if (!spec)
throw Error("invalid outputs specifier '%s'", s);
return std::move(*spec);
using namespace std::string_view_literals;
if (s == "*"sv)
return OutputsSpec::All{};
auto names = splitString<StringSet>(s, ",");
for (const auto & name : names)
checkName(name);
return OutputsSpec::Names{std::move(names)};
}
std::optional<std::pair<std::string_view, ExtendedOutputsSpec>> ExtendedOutputsSpec::parseOpt(std::string_view s)