diff --git a/secsie/__init__.py b/secsie/__init__.py index 2d69b98..adcc684 100644 --- a/secsie/__init__.py +++ b/secsie/__init__.py @@ -10,7 +10,7 @@ Supports secsie and ini formats. Not suitable for writing .ini files, but reads them just fine. """ -__version__ = '2.1.1' +__version__ = '2.1.2' __author__ = 'Noah Broyles' __all__ = [ 'InvalidSyntax', @@ -97,12 +97,13 @@ def parse_config(config: str, mode: str = 'secsie') -> dict: lineno = 0 for line in lines: lineno += 1 + # Check for whole line comments + if line.startswith('#') or line.startswith(';'): + continue # Handle inline comments - line = line.split('#')[0].strip() + line = line.split(' #')[0].strip() if line == '': # Skip blank lines continue - if line.startswith('#') or line.startswith(';'): - continue # Check to see if this is a section if MODES[mode]["SECTION_EX"].match(line): c_section = MODES[mode]["SECTION_EX"].findall(line)[0] diff --git a/tests/test_whitespace.py b/tests/test_whitespace.py index 35913da..a64cd60 100644 --- a/tests/test_whitespace.py +++ b/tests/test_whitespace.py @@ -20,3 +20,16 @@ def test_whitespace_insensitivity(): assert config['key2'] == 'value2' assert config['ur'] == 'cute' assert config['space-values'] == 'this should be chilll bro' + + +def test_comment_support(): + """ + Tests that secsie ignores octothorpes in values + """ + config = secsie.parse_config( + """ + password = som#$scure # this should be amazing + """ + ) + + assert config['password'] == 'som#$scure'