Skip to content

Commit

Permalink
Fix: Schema key containing - not producing matches (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutsu3 committed Oct 9, 2021
1 parent c7c62c5 commit b38e715
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion linkify_it/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


def _escape_re(string):
return re.sub(r"[.?*+^$[\]\\(){}|-]", "\\$&", string)
return re.sub(r"([.?*+^$[\]\\(){}|-])", r"\\\1", string)


def _index_of(text, search_value):
Expand Down
12 changes: 12 additions & 0 deletions test/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,15 @@ def test_api_shoud_accept_triple_minus():
linkifyit = LinkifyIt(None, {"---": True})

assert linkifyit.match("http://e.com/foo---bar")[0].text == "http://e.com/foo"


# issue #25. Schema key containing - not producing matches
@pytest.mark.parametrize(
"escape_str",
{".", "?", "*", "+", "^", "$", "[", "]", "\\", "(", ")", "{", "}", "|", "-"},
)
def test_api_add_alias_rule_with_excape_re_string(escape_str):
linkifyit = LinkifyIt()

linkifyit.add("foo{}bar:".format(escape_str), "http:")
assert linkifyit.test("Check foo{}bar://test".format(escape_str)) is True

0 comments on commit b38e715

Please sign in to comment.