diff --git a/courlan/core.py b/courlan/core.py index 92c9847..e12a6b4 100644 --- a/courlan/core.py +++ b/courlan/core.py @@ -33,7 +33,8 @@ FIND_LINKS_REGEX = re.compile(r"]+?>", re.I) HREFLANG_REGEX = re.compile(r'hreflang=["\']?([a-z-]+)', re.I) -LINK_REGEX = re.compile(r'href=["\']?([^ ]+?)(["\' >])', re.I) +# *? so empty href="" / href='' do not capture the closing quote as the URL +LINK_REGEX = re.compile(r'href=["\']?([^ ]*?)(["\' >])', re.I) def check_url( diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 2983d5b..12142b7 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -1248,6 +1248,21 @@ def test_extraction(): # hreflang matches the target language but the tag has no href pagecontent = 'no href' assert not extract_links(pagecontent, "https://test.com/", False, language="de") + # empty quoted href must not capture the closing quote as a path (/%27) + pagecontent = "x" + assert extract_links(pagecontent, "https://example.org", False) == { + "https://example.org" + } + assert extract_links(pagecontent, "https://example.org", no_filter=True) == { + "https://example.org" + } + pagecontent = 'x' + assert extract_links(pagecontent, "https://example.org", False) == { + "https://example.org" + } + assert extract_links(pagecontent, "https://example.org", no_filter=True) == { + "https://example.org" + } # link known under another form pagecontent = '' assert len(extract_links(pagecontent, "https://test.org", False)) == 1