Skip to content

Commit

Permalink
Bug 1582122 - Do not fail if config line without "=" r=glob
Browse files Browse the repository at this point in the history
Reviewers: glob

Reviewed By: glob

Bug #: 1582122

Differential Revision: https://phabricator.services.mozilla.com/D46757
zalun committed Sep 23, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f24103f commit be9564b
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion moz-phab
Original file line number Diff line number Diff line change
@@ -416,7 +416,11 @@ def parse_config(config_list, filter_func=None):
except UnicodeDecodeError:
pass

name, value = line.split("=", 1)
try:
name, value = line.split("=", 1)
except ValueError:
continue

name = name.strip()
value = value.strip()
if filter_func is None or (callable(filter_func) and filter_func(name, value)):
20 changes: 20 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -416,3 +416,23 @@ def test_simple_cache():

cache.delete("something")
assert cache.get("something") is None


def test_parse_config():
res = mozphab.parse_config(
["key=value 1", "key2 = value2 ", "key3=", "key4=one=two=three"]
)
assert res == dict(key="value 1", key2="value2", key3="", key4="one=two=three")


def test_parse_config_key_only():
assert mozphab.parse_config(["key"]) == dict()


def test_parse_config_with_filter():
def _filter(name, value):
if name != "out":
return True

res = mozphab.parse_config(["imin=I'm in", "out=not here"], _filter)
assert res == dict(imin="I'm in")

0 comments on commit be9564b

Please sign in to comment.