From a576a045e1706ad7b441f685fee5e15db0afc9ef Mon Sep 17 00:00:00 2001 From: Humorous Baby <44451911+HumorBaby@users.noreply.github.com> Date: Sat, 26 Jan 2019 20:47:31 -0500 Subject: [PATCH] config: support comma in config ListAttribute item This is a first step towards completing #1455, since, as @dgw mentioned, to do so would require accepting commas in a single entry of `ListAttribute`. Items entered through the wizard do not need to be escaped manually. Items configured in the `.cfg` file manually require an escaped command, like `\,`. The prompt has also been changed such that the items are now surrounded by quotes so that one can differentiate items that may contains commas. The following scenarios were tested (using the `url.py` module, specifically the `exclude` setting): 1. Wizard, setting items when there is no default (preexisting items); mix of w/ commas and w/o commas 2. Wizard, replacing existing items when a default exists; mix of w/ commas and w/o commas 3. Wizard, extending the current default list; mix of w/ commas and w/o commas 4. Manual edit, setting items; w/ commas (manually escaped) and w/o commas 5. Wizard, setting items w/o default; no commas Relevant tests have also been updated/added: 1. Item with comma remains single item: - `test_listattribute_with_value_containing_comma` 2. Item with backslash is correctly serialized/parsed: - `test_listattribute_with_value_containing_backslash` - `test_listattribute_with_value_ending_in_backslash` --- sopel/config/types.py | 26 ++++++++++++++++---------- test/test_config.py | 10 +++++++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/sopel/config/types.py b/sopel/config/types.py index 2da4fe2f9c..5432549326 100644 --- a/sopel/config/types.py +++ b/sopel/config/types.py @@ -27,6 +27,7 @@ from __future__ import unicode_literals, absolute_import, print_function, division import os.path +import re import sys from sopel.tools import get_input @@ -218,16 +219,18 @@ def __init__(self, name, strip=True, default=None): self.strip = strip def parse(self, value): - value = list(filter(None, value.split(','))) + value = list(filter(None, re.split(r'(?