From d239fcf936bd5950399da2edb9612baadc7ee3e6 Mon Sep 17 00:00:00 2001 From: Ashar Khan Date: Wed, 10 Sep 2025 09:17:16 -0400 Subject: [PATCH] Fix get_meta_refresh to correctly resolve relative URLs using tag (#7047) --- scrapy/utils/response.py | 2 +- tests/test_utils_response.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scrapy/utils/response.py b/scrapy/utils/response.py index b6550432c..8b2417bfb 100644 --- a/scrapy/utils/response.py +++ b/scrapy/utils/response.py @@ -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] diff --git a/tests/test_utils_response.py b/tests/test_utils_response.py index 179ca49e4..0aeb5594f 100644 --- a/tests/test_utils_response.py +++ b/tests/test_utils_response.py @@ -67,9 +67,23 @@ if(!checkCookies()){ """, ) + r4 = HtmlResponse( + "http://www.example.com", + body=b""" + + Dummy + + + blahablsdfsal& + """, + ) 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():