From 039d3feea718974fc6dd0d690c0a2c6d8071b4ae Mon Sep 17 00:00:00 2001 From: PobreGato <315121269+pobregat0@users.noreply.github.com> Date: Mon, 31 Aug 2026 03:12:39 +0300 Subject: [PATCH] return false instead of throwing on a url with nothing after the schema --- libi2pd/HTTP.cpp | 1 + tests/test-http-url.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/libi2pd/HTTP.cpp b/libi2pd/HTTP.cpp index f5c0b213..43a110bc 100644 --- a/libi2pd/HTTP.cpp +++ b/libi2pd/HTTP.cpp @@ -133,6 +133,7 @@ namespace http } /* hostname[:port][/path] */ + if (pos_p >= url.length ()) return false; /* nothing left after schema or user part */ if (url.at(pos_p) == '[') // ipv6 { auto pos_b = url.find(']', pos_p); diff --git a/tests/test-http-url.cpp b/tests/test-http-url.cpp index a5021c43..061c83ce 100644 --- a/tests/test-http-url.cpp +++ b/tests/test-http-url.cpp @@ -125,6 +125,12 @@ int main() { assert(url->frag == "frag"); delete url; + /* nothing after the schema or the user part: must not throw */ + url = new URL; + assert(url->parse("http://") == false); + assert(url->parse("http://user@") == false); + delete url; + return 0; }