Skip to content

Commit

Permalink
fix: do not escape hash symbol in regex (#7)
Browse files Browse the repository at this point in the history
* fix: do not escape hash symbol in regex
  • Loading branch information
noahnu authored May 31, 2021
1 parent e7533fb commit b14c44e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/unison_gitignore/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,7 @@ def __repr__(self):

def __str__(self):
s = "-ignore" if self.include else "-ignorenot"
escaped_regex = self.regex.replace("\\~", "~").replace("\\-", "-")
escaped_regex = (
self.regex.replace("\\~", "~").replace("\\-", "-").replace("\\#", "#")
)
return f"{s}=Regex {escaped_regex}"
6 changes: 6 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def test_root_path_removes_slash():
assert parsed[0].anchor_path == ""


def test_hash_should_not_be_escaped():
parsed = GitIgnoreToUnisonIgnore(".#*").parse_gitignore(StringIO(".#file"))
assert len(parsed) == 1
assert str(parsed[0]) == r"-ignore=Regex ^.#*/(.+/)?\.#file(/.*)?$"


def test_accepts_array_of_strings():
parsed = GitIgnoreToUnisonIgnore("/").parse_gitignore(["test1.py", "test2.py"])
assert len(parsed) == 2
Expand Down

0 comments on commit b14c44e

Please sign in to comment.