Fix recursive definitions in env vars not expanded

This commit is contained in:
Kovid Goyal
2022-03-07 11:07:26 +05:30
parent 6ff69c88df
commit 68df13d3fe
3 changed files with 21 additions and 5 deletions

View File

@@ -33,11 +33,21 @@ from .options.types import Options as SSHOptions
from .options.utils import DELETE_ENV_VAR
# See https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html
quote_pat = re.compile('([\\`"\n])')
def quote_env_val(x: str) -> str:
x = quote_pat.sub(r'\\\1', x)
x = x.replace('$(', r'\$(') # prevent execution with $()
return f'"{x}"'
def serialize_env(env: Dict[str, str], base_env: Dict[str, str]) -> bytes:
lines = []
def a(k: str, val: str) -> None:
lines.append(f'export {k}={shlex.quote(val)}')
lines.append(f'export {shlex.quote(k)}={quote_env_val(val)}')
for k in sorted(env):
v = env[k]