Skip to content

Commit

Permalink
fix processing of lines starting with "rem"
Browse files Browse the repository at this point in the history
iniparse defaults to treating lines starting with "rem" as comments.
Therefore change the default comment matching scheme to allow
parameters like "remote = 1" for example.

Also allow '%' as a comment character which will then allow
processing of mercurial config files which can use "%include"
and "%unset" directives.

Fixes issue #39
  • Loading branch information
pixelb committed Nov 23, 2016
1 parent fdf7dc7 commit 58118c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crudini
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class LockedFile(FileLock):
class CrudiniConfigParser(iniparse.RawConfigParser):
def __init__(self, preserve_case=False):
iniparse.RawConfigParser.__init__(self)
# Without the following we can't have params starting with "rem"!
# We ignore lines starting with '%' which mercurial uses to include
iniparse.change_comment_syntax('%;#', allow_rem=False)
if preserve_case:
self.optionxform = str

Expand Down
7 changes: 7 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ printf '%s\n' '#comment' '[section1]' > test.ini
test "$(crudini --get test.ini)" = 'section1' || fail
ok

# Ensure we handle comments correctly
printf '%s\n' '[DEFAULT]' '#c1' ';c2' '%inc1' > test.ini
test "$(crudini --get test.ini)" = '' || fail
printf '%s\n' '[section1]' 'remote=1' > test.ini
test "$(crudini --get test.ini 'section1')" = 'remote' || fail
ok

# missing bits
:> test.ini
crudini --get missing.ini 2>/dev/null && fail
Expand Down

0 comments on commit 58118c2

Please sign in to comment.