Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: fix web pages with non-English URLs failing to load (#9721)
Nilay14ffa5988b96
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.pyindex d256278e0af..dc2774204c1 100644--- a/studio/backend/core/inference/tools.py+++ b/studio/backend/core/inference/tools.py@@ -11026,6 +11026,9 @@ _HEX_PAIR_RE = re.compile(r"[0-9A-Fa-f]{2}")# Raw download cap > _MAX_PAGE_CHARS since SSR pages embed large <head> sections# stripped during conversion; 512 KB still reaches article content._MAX_FETCH_BYTES = 512 * 1024+# "%" is safe so an already-encoded URL is not re-encoded into %25.+_IRI_PATH_SAFE = "/%:@!$&'()*+,;="+_IRI_QUERY_SAFE = "/%:@!$&'()*+,;=?"# PDF cross-reference data lives at EOF, so extraction needs the whole body._MAX_PDF_FETCH_BYTES = 10 * 1024 * 1024_MAX_WEB_PDF_PAGES = 50@@ -11562,7 +11565,7 @@ def _fetch_url_raw(try:from urllib.error import HTTPError as _HTTPError- from urllib.parse import urljoin, urlunparse+ from urllib.parse import quote, urljoin, urlunparsemax_bytes = _MAX_FETCH_BYTEScurrent_url = url@@ -11574,6 +11577,12 @@ def _fetch_url_raw(if budget_error is not None:return budget_error, "", ""cp = urlparse(current_url)+ # http.client rejects a non-ASCII selector outright.+ cp = cp._replace(+ path = quote(cp.path, safe = _IRI_PATH_SAFE),+ params = quote(cp.params, safe = _IRI_PATH_SAFE),+ query = quote(cp.query, safe = _IRI_QUERY_SAFE),+ )# Bracket IPv6 so the netloc stays a valid URL.validated_netloc = f"[{current_host}]" if ":" in current_host else current_hostif cp.port:diff --git a/studio/backend/tests/test_web_fetch_scheme_normalization.py b/studio/backend/tests/test_web_fetch_scheme_normalization.pyindex b4dad837e6b..0f626675c22 100644--- a/studio/backend/tests/test_web_fetch_scheme_normalization.py+++ b/studio/backend/tests/test_web_fetch_scheme_normalization.py@@ -168,3 +168,46 @@ def test_schemeless_github_repo_still_routes_to_readme_api():assert tools._github_repo_readme_api_url(normalized) == ("https://api.github.com/repos/unslothai/unsloth/readme")+++def _request_url_for(monkeypatch, url):+ from core.inference import tools++ seen = {}++ class _Opener:+ def open(+ self,+ req,+ timeout = None,+ ):+ seen["url"] = req.full_url+ raise RuntimeError("captured")++ monkeypatch.setattr(tools, "_resolve_with_budget", lambda *a: (True, "", "93.184.216.34"))+ monkeypatch.setattr(tools.urllib.request, "build_opener", lambda *a: _Opener())+ tools._fetch_url_raw(url, timeout = 5)+ return seen.get("url", "")+++def test_non_ascii_path_is_percent_encoded(monkeypatch):+ got = _request_url_for(monkeypatch, "https://de.wikipedia.org/wiki/Künstliche_Intelligenz")+ assert "K%C3%BCnstliche" in got+ assert got.isascii(), got+++def test_non_ascii_query_is_percent_encoded(monkeypatch):+ got = _request_url_for(monkeypatch, "https://example.com/s?q=café")+ assert "caf%C3%A9" in got+ assert got.isascii(), got+++def test_already_encoded_url_is_not_double_encoded(monkeypatch):+ got = _request_url_for(monkeypatch, "https://de.wikipedia.org/wiki/K%C3%BCnstliche_Intelligenz")+ assert "K%C3%BCnstliche" in got+ assert "%25" not in got+++def test_ascii_url_is_unchanged(monkeypatch):+ got = _request_url_for(monkeypatch, "https://example.com/a/b?x=1&y=2")+ assert got.endswith("/a/b?x=1&y=2"), got