Skip to content

Commit 08f0daf

Browse files
authored
fix(benchmark): scheme validation to ollama-url (closes #166) (#274)
Add urllib.parse.urlparse to benchmark-local.py and validate that the provided --ollama-url uses either the http or https scheme. Fix arbitrary URI handling where the script could previously access local files (file://) or other unsupported protocols. If the scheme is invalid, parser.error is called to exit cleanly with a clear message.
1 parent 7b21459 commit 08f0daf

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎benchmarks/benchmark-local.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import re
1616
import time
1717
import urllib.request
18+
import urllib.parse
1819
from pathlib import Path
1920

2021
ROOT = Path(__file__).parent.parent
@@ -149,6 +150,11 @@ def main():
149150
parser.add_argument("--repeat", type=int, default=1, help="Runs per cell; median reported (default: 1)")
150151
parser.add_argument("--ollama-url", default="http://localhost:11434", help="Ollama base URL")
151152
args = parser.parse_args()
153+
154+
parsed_url = urllib.parse.urlparse(args.ollama_url)
155+
if parsed_url.scheme not in ("http", "https"):
156+
parser.error(f"Invalid --ollama-url scheme: '{parsed_url.scheme}'. Only 'http' and 'https' are supported.")
157+
152158
run(args.model, args.repeat, args.ollama_url)
153159

154160

0 commit comments

Comments
 (0)