From 3389a3d4c361cd8dc7c71587dfef4955915567d5 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Thu, 17 Nov 2022 22:20:30 -0500 Subject: [PATCH] Improved text configuration parsing (#768) --- apprise/config/ConfigBase.py | 2 +- test/test_config_base.py | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/apprise/config/ConfigBase.py b/apprise/config/ConfigBase.py index 50536c66..5babd38e 100644 --- a/apprise/config/ConfigBase.py +++ b/apprise/config/ConfigBase.py @@ -548,7 +548,7 @@ class ConfigBase(URLBase): # Define what a valid line should look like valid_line_re = re.compile( r'^\s*(?P([;#]+(?P.*))|' - r'(\s*(?P[^=]+)=|=)?\s*' + r'(\s*(?P[a-z0-9, \t_-]+)\s*=|=)?\s*' r'(?P[a-z0-9]{2,9}://.*)|' r'include\s+(?P.+))?\s*$', re.I) diff --git a/test/test_config_base.py b/test/test_config_base.py index 579fa1ff..1492fc88 100644 --- a/test/test_config_base.py +++ b/test/test_config_base.py @@ -325,7 +325,7 @@ def test_config_base_config_parse_text(): assert isinstance(result, list) assert len(result) == 0 - # There was 1 valid entry + # There were no include entries defined assert len(config) == 0 # Test case where a comment is on it's own line with nothing else @@ -337,6 +337,56 @@ def test_config_base_config_parse_text(): # There were no include entries defined assert len(config) == 0 + # Verify our tagging works when multiple tags are provided + result, config = ConfigBase.config_parse_text(""" + tag1, tag2, tag3=json://user:pass@localhost + """) + + assert isinstance(result, list) + assert len(result) == 1 + assert len(result[0].tags) == 3 + assert 'tag1' in result[0].tags + assert 'tag2' in result[0].tags + assert 'tag3' in result[0].tags + + +def test_config_base_config_parse_text_with_url(): + """ + API: ConfigBase.config_parse_text object_with_url + + """ + # Here is a similar result set however this one has an invalid line + # in it which invalidates the entire file + result, config = ConfigBase.config_parse_text(""" + # Test a URL that has a URL as an argument + json://user:pass@localhost?+arg=http://example.com?arg2=1&arg3=3 + """) + + # No tag is parsed, but our URL successfully parses as is + + assert isinstance(result, list) + assert len(result) == 1 + assert len(result[0].tags) == 0 + + # Verify our URL is correctly captured + assert '%2Barg=http%3A%2F%2Fexample.com%3Farg2%3D1' in result[0].url() + assert 'json://user:pass@localhost/' in result[0].url() + + # There were no include entries defined + assert len(config) == 0 + + # Pass in our configuration again + result, config = ConfigBase.config_parse_text(result[0].url()) + + # Verify that our results repeat themselves + assert isinstance(result, list) + assert len(result) == 1 + assert len(result[0].tags) == 0 + assert '%2Barg=http%3A%2F%2Fexample.com%3Farg2%3D1' in result[0].url() + assert 'json://user:pass@localhost/' in result[0].url() + + assert len(config) == 0 + def test_config_base_config_parse_yaml(): """