diff --git a/src/libexpr/get-drvs.cc b/src/libexpr/get-drvs.cc index c4a2b00af..a15f1085d 100644 --- a/src/libexpr/get-drvs.cc +++ b/src/libexpr/get-drvs.cc @@ -367,7 +367,26 @@ static std::string addToPath(const std::string & s1, std::string_view s2) return s1.empty() ? std::string(s2) : s1 + "." + s2; } -static std::regex attrRegex("[A-Za-z_][A-Za-z0-9-_+]*"); +static bool isAttrPathComponent(std::string_view symbol) +{ + if (symbol.empty()) + return false; + + /* [A-Za-z_] */ + unsigned char first = symbol[0]; + if (!((first >= 'A' && first <= 'Z') || (first >= 'a' && first <= 'z') || first == '_')) + return false; + + /* [A-Za-z0-9-_+]* */ + for (unsigned char c : symbol.substr(1)) { + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_' + || c == '+') + continue; + return false; + } + + return true; +} static void getDerivations( EvalState & state, @@ -400,7 +419,7 @@ static void getDerivations( std::string_view symbol{state.symbols[i->name]}; try { debug("evaluating attribute '%1%'", symbol); - if (!std::regex_match(symbol.begin(), symbol.end(), attrRegex)) + if (!isAttrPathComponent(symbol)) continue; std::string pathPrefix2 = addToPath(pathPrefix, symbol); if (combineChannels)