Skip to content

Commit

Permalink
vsenv: fix handling of env variables with only '='
Browse files Browse the repository at this point in the history
Some CI's include variables containing the issue description, like
GitLab's CI_MERGE_REQUEST_DESCRIPTION. The description itself can
have multiple lines and any kind of content.
If one of these lines is '=========', it will leave k empty
when it's split by '='S.

Also improve how lines without '=' are parsed by checking the
parts of the split by '=' rather than trying to unpack a 1 value
array and handle the exception
  • Loading branch information
ylatuya committed Sep 17, 2024
1 parent 2b80d4c commit d0241ce
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions mesonbuild/utils/vsenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,22 @@ def _setup_vsenv(force: bool) -> bool:
continue
if not bat_line:
continue
parts = bat_line.split('=', 1)
if len(parts) != 2:
continue
k, v = parts
# Some CI's include variables containing the issue description, like
# GitLab's CI_MERGE_REQUEST_DESCRIPTION. The description itself can
# have multiple lines and any kind of content.
# If one of these lines is '=========', it will leave k empty
# when it's split by '='
if k is None or v is None:
continue
try:
k, v = bat_line.split('=', 1)
os.environ[k] = v
except ValueError:
# there is no "=", ignore junk data
# Ignore errors from junk data returning invalid environment variable names
pass
else:
os.environ[k] = v
return True

def setup_vsenv(force: bool = False) -> bool:
Expand Down

0 comments on commit d0241ce

Please sign in to comment.