Skip to content

Commit

Permalink
config: remove trailing comma when using breaklines
Browse files Browse the repository at this point in the history
  • Loading branch information
Exirel committed Jun 3, 2019
1 parent 301ec42 commit 4cae19a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions sopel/config/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,11 @@ def parse(self, value):
multi-line string.
"""
if "\n" in value:
items = value.splitlines()
items = [
# remove trailing comma
# because `value,\nother` is valid in Sopel 7.x
item.strip(self.DELIMITER).strip()
for item in value.splitlines()]
else:
# this behavior will be:
# - Discouraged in Sopel 7.x (in the documentation)
Expand All @@ -282,7 +286,7 @@ def parse(self, value):
items = value.split(self.DELIMITER)

value = list(filter(None, items))
if self.strip:
if self.strip: # deprecate strip option in Sopel 8.x
return [v.strip() for v in value]
else:
return value
Expand Down
8 changes: 4 additions & 4 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
[spam]
eggs = one, two, three, four, and a half
bacons = grilled
burn out
greasy, fat, and tasty
burn out,
, greasy, fat, and tasty
cheese =
cheddar
reblochon
Expand Down Expand Up @@ -126,10 +126,10 @@ def test_listattribute_with_value_ending_in_special_chars(fakeconfig):
assert fakeconfig.fake.listattr == ['spam', 'egg', 'sausage\\', 'bacon']

fakeconfig.fake.listattr = ['spam', 'egg', 'sausage,', 'bacon']
assert fakeconfig.fake.listattr == ['spam', 'egg', 'sausage,', 'bacon']
assert fakeconfig.fake.listattr == ['spam', 'egg', 'sausage', 'bacon']

fakeconfig.fake.listattr = ['spam', 'egg', 'sausage,,', 'bacon']
assert fakeconfig.fake.listattr == ['spam', 'egg', 'sausage,,', 'bacon']
assert fakeconfig.fake.listattr == ['spam', 'egg', 'sausage', 'bacon']


def test_listattribute_with_value_containing_adjacent_special_chars(fakeconfig):
Expand Down

0 comments on commit 4cae19a

Please sign in to comment.