Make sure base URL for resolve_url is absolute

This commit is contained in:
Florian Bruhin 2016-08-05 17:12:09 +02:00
parent 7a65559cce
commit 68595e1736
2 changed files with 9 additions and 0 deletions

View File

@ -509,6 +509,9 @@ class WebElementWrapper(collections.abc.MutableMapping):
Return:
A QUrl with the absolute URL, or None.
"""
if baseurl.isRelative():
raise ValueError("Need an absolute base URL!")
for attr in ['href', 'src']:
if attr in self:
text = self[attr].strip()

View File

@ -958,3 +958,9 @@ def test_resolve_url(attributes, expected):
elem = get_webelem(attributes=attributes)
baseurl = QUrl('http://www.example.com/')
assert elem.resolve_url(baseurl) == expected
def test_resolve_url_relative_base():
elem = get_webelem(attributes={'href': 'foo'})
with pytest.raises(ValueError):
elem.resolve_url(QUrl('base'))