mirror of https://github.com/scrapy/scrapy.git
Fix get_meta_refresh to correctly resolve relative URLs using <base> tag (#7047)
This commit is contained in:
parent
2ad81a0ef8
commit
d239fcf936
|
|
@ -48,7 +48,7 @@ def get_meta_refresh(
|
|||
if response not in _metaref_cache:
|
||||
text = response.text[0:4096]
|
||||
_metaref_cache[response] = html.get_meta_refresh(
|
||||
text, response.url, response.encoding, ignore_tags=ignore_tags
|
||||
text, get_base_url(response), response.encoding, ignore_tags=ignore_tags
|
||||
)
|
||||
return _metaref_cache[response]
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,23 @@ if(!checkCookies()){
|
|||
</script>
|
||||
""",
|
||||
)
|
||||
r4 = HtmlResponse(
|
||||
"http://www.example.com",
|
||||
body=b"""
|
||||
<html>
|
||||
<head><title>Dummy</title>
|
||||
<base href="http://www.another-domain.com/base/path/">
|
||||
<meta http-equiv="refresh" content="5;url=target.html"</head>
|
||||
<body>blahablsdfsal&</body>
|
||||
</html>""",
|
||||
)
|
||||
assert get_meta_refresh(r1) == (5.0, "http://example.org/newpage")
|
||||
assert get_meta_refresh(r2) == (None, None)
|
||||
assert get_meta_refresh(r3) == (None, None)
|
||||
assert get_meta_refresh(r4) == (
|
||||
5.0,
|
||||
"http://www.another-domain.com/base/path/target.html",
|
||||
)
|
||||
|
||||
|
||||
def test_get_base_url():
|
||||
|
|
|
|||
Loading…
Reference in New Issue