Only consider variable names with alpanumeric characters, underscore
and parentheses. This avoids most problems when parsing output
containing multi-line variable values with arbitrary text.
In GitLab CI, one of the environment variables is CI_COMMIT_MESSAGE. In the commit immediately following this commit there is an URL containing an equal sign that caused the error below:
Set-Content : An object at the specified path
env:\https://docs.microsoft.com/en-us/visualstudio/ide/how-to-configure-projects-to-target-platforms?view does not
exist, or has been filtered by the -Include or -Exclude parameter.
At line:3 char:5
+ Set-Content "env:\$($matches[1])" $matches[2];
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (System.String[]:String[]) [Set-Content], Exception
+ FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.SetContentCommand
- cmd.exe /c "call `"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat`" $TARGET_ARCH && set > %temp%\vcvars.txt";
- >-
Get-Content "$env:temp\vcvars.txt" | Foreach-Object {
- if ($_ -match "^(.*?)=(.*)$") {
+ if ($_ -match "^([A-Za-z0-9_()]*)=(.*)$") {
Set-Content "env:\$($matches[1])" $matches[2];
}
}