Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion courlan/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

FIND_LINKS_REGEX = re.compile(r"<a\s+[^<>]+?>", 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(
Expand Down
15 changes: 15 additions & 0 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,21 @@ def test_extraction():
# hreflang matches the target language but the tag has no href
pagecontent = '<html><a hreflang="de-DE">no href</a></html>'
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 = "<html><a href=''>x</a></html>"
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 = '<html><a href="">x</a></html>'
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 = '<html><a href="https://test.org/example"/><a href="https://test.org/example/&"/></html>'
assert len(extract_links(pagecontent, "https://test.org", False)) == 1
Expand Down
Loading