mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 818554 - Handle empty variables when parsing mozconfig output; r=glandium
DONTBUILD (NPOTB)
This commit is contained in:
parent
963b4c0ea2
commit
d1484b4697
@ -299,7 +299,6 @@ class MozconfigLoader(ProcessExecutionMixin):
|
||||
|
||||
name = in_variable
|
||||
value = None
|
||||
|
||||
if in_variable:
|
||||
# Reached the end of a multi-line variable.
|
||||
if line.endswith("'") and not line.endswith("\\'"):
|
||||
@ -313,24 +312,25 @@ class MozconfigLoader(ProcessExecutionMixin):
|
||||
equal_pos = line.find('=')
|
||||
|
||||
if equal_pos < 1:
|
||||
# TODO log warning
|
||||
# TODO log warning?
|
||||
continue
|
||||
|
||||
name = line[0:equal_pos]
|
||||
has_quote = line[equal_pos + 1] == "'"
|
||||
value = line[equal_pos + 1:]
|
||||
|
||||
if has_quote:
|
||||
value = line[equal_pos + 2:]
|
||||
else:
|
||||
value = line[equal_pos + 1:]
|
||||
if len(value):
|
||||
has_quote = value[0] == "'"
|
||||
|
||||
# Lines with a quote not ending in a quote are multi-line.
|
||||
if has_quote and not value.endswith("'"):
|
||||
in_variable = name
|
||||
current.append(value)
|
||||
continue
|
||||
else:
|
||||
value = value[:-1] if has_quote else value
|
||||
if has_quote:
|
||||
value = value[1:]
|
||||
|
||||
# Lines with a quote not ending in a quote are multi-line.
|
||||
if has_quote and not value.endswith("'"):
|
||||
in_variable = name
|
||||
current.append(value)
|
||||
continue
|
||||
else:
|
||||
value = value[:-1] if has_quote else value
|
||||
|
||||
assert name is not None
|
||||
|
||||
|
@ -274,7 +274,7 @@ class TestMozconfigLoader(unittest.TestCase):
|
||||
'single': '1'
|
||||
})
|
||||
|
||||
def test_read_topsrcdir_defines(self):
|
||||
def test_read_topsrcdir_defined(self):
|
||||
"""Ensure $topsrcdir references work as expected."""
|
||||
with NamedTemporaryFile(mode='w') as mozconfig:
|
||||
mozconfig.write('TEST=$topsrcdir')
|
||||
@ -285,3 +285,14 @@ class TestMozconfigLoader(unittest.TestCase):
|
||||
|
||||
self.assertEqual(result['env']['added']['TEST'], loader.topsrcdir)
|
||||
|
||||
def test_read_empty_variable_value(self):
|
||||
"""Ensure empty variable values are parsed properly."""
|
||||
with NamedTemporaryFile(mode='w') as mozconfig:
|
||||
mozconfig.write('EMPTY=\n')
|
||||
mozconfig.flush()
|
||||
|
||||
result = self.get_loader().read_mozconfig(mozconfig.name)
|
||||
|
||||
self.assertIn('EMPTY', result['env']['added'])
|
||||
self.assertEqual(result['env']['added']['EMPTY'], '')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user