Skip to content

Commit

Permalink
Handle #'s in values, e.g passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
noahbroyles committed Jul 6, 2022
1 parent 1a7d453 commit 01681a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions secsie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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]
Expand Down
13 changes: 13 additions & 0 deletions tests/test_whitespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 01681a3

Please sign in to comment.