Merge remote-tracking branch 'origin/fix/utils-qq-image-preserve-scheme' into validation/test-build-with-fixes

# Conflicts:
#	tests/unit_tests/utils/test_image.py
This commit is contained in:
huanghuoguoguo
2026-05-16 10:44:23 +08:00
3 changed files with 15 additions and 5 deletions

View File

@@ -145,7 +145,8 @@ def get_qq_image_downloadable_url(image_url: str) -> tuple[str, dict]:
"""获取QQ图片的下载链接"""
parsed = urlparse(image_url)
query = parse_qs(parsed.query)
return f'http://{parsed.netloc}{parsed.path}', query
scheme = parsed.scheme or 'http'
return f'{scheme}://{parsed.netloc}{parsed.path}', query
async def get_qq_image_bytes(image_url: str, query: dict = {}) -> tuple[bytes, str]:

View File

@@ -0,0 +1 @@

View File

@@ -56,13 +56,21 @@ class TestGetQQImageDownloadableUrl:
# Fragment is not included in query string parsing
assert "http://example.com/image.jpg" in result_url
def test_https_url(self):
"""Parse HTTPS URL - note: function returns http:// regardless of input scheme."""
def test_https_url_preserves_scheme(self):
"""Parse HTTPS URL without downgrading the scheme."""
url = "https://example.com/image.jpg"
result_url, query = get_qq_image_downloadable_url(url)
# The function constructs URL with http:// scheme
assert "example.com/image.jpg" in result_url
assert result_url == "https://example.com/image.jpg"
assert query == {}
def test_missing_scheme_defaults_to_http(self):
"""Parse scheme-less URL with the existing HTTP default."""
url = "example.com/image.jpg?param=value"
result_url, query = get_qq_image_downloadable_url(url)
assert result_url == "http://example.com/image.jpg"
assert query == {"param": ["value"]}
class TestExtractB64AndFormat: