diff --git a/linkify_it/main.py b/linkify_it/main.py index b06a7b3..8d9254b 100644 --- a/linkify_it/main.py +++ b/linkify_it/main.py @@ -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): diff --git a/test/test_apis.py b/test/test_apis.py index 076df57..093f293 100644 --- a/test/test_apis.py +++ b/test/test_apis.py @@ -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