fix(web_fetch): sanitize URL to strip markdown backticks and quotes before validation
LLM-generated tool calls may wrap URLs in markdown backticks or quotes (e.g. \https://example.com\), causing urlparse to produce empty scheme and netloc, which leads to all fetch attempts failing silently. Add URL cleaning at the top of WebFetchTool.execute to strip whitespace, backticks, double quotes, and single quotes, plus an early rejection guard for non-http(s) URLs after cleaning.
This commit is contained in:
@@ -388,6 +388,9 @@ class WebFetchTool(Tool):
|
||||
max_chars: int | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Any:
|
||||
url = url.strip().strip("`").strip('"').strip("'")
|
||||
if not (url.startswith("http://") or url.startswith("https://")):
|
||||
return json.dumps({"error": "Invalid URL after cleaning", "url": url}, ensure_ascii=False)
|
||||
extract_mode = kwargs.pop("extractMode", extract_mode)
|
||||
max_chars = kwargs.pop("maxChars", max_chars) or self.max_chars
|
||||
is_valid, error_msg = _validate_url_safe(url)
|
||||
|
||||
Reference in New Issue
Block a user