nix dev-shell: Improve bash output parsing

Fixes handling of '=' in unquoted strings and escaped characters in
$'...' strings.
This commit is contained in:
Eelco Dolstra 2019-11-12 12:45:48 +01:00
parent 2c1e05ae93
commit 8d2eb1ff56
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -29,6 +29,8 @@ BuildEnvironment readEnvironment(const Path & path)
std::set<std::string> exported;
debug("reading environment file '%s'", path);
auto file = readFile(path);
auto pos = file.cbegin();
@ -41,10 +43,10 @@ BuildEnvironment readEnvironment(const Path & path)
R"re((?:="((?:[^"\\]|\\.)*)")?\n)re");
static std::string simpleStringRegex =
R"re((?:[a-zA-Z0-9_/:\.\-1\+]*))re";
R"re((?:[a-zA-Z0-9_/:\.\-\+=]*))re";
static std::string quotedStringRegex =
R"re((?:\$?'[^']*'))re";
R"re((?:\$?'(?:[^'\\]|\\[abeEfnrtv\\'"?])*'))re";
static std::string arrayRegex =
R"re((?:\(( *\[[^\]]+\]="(?:[^"\\]|\\.)*")*\)))re";