From 50f1a89e65c4e73630654430918221a637aecba5 Mon Sep 17 00:00:00 2001 From: long_long_float Date: Mon, 6 Sep 2021 01:02:12 +0900 Subject: [PATCH 1/2] Add an error check for empty path of an URL --- libraries/HTTPClient/src/HTTPClient.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index e7a8ecb8f4f..a956eaead87 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -261,6 +261,10 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol) url.remove(0, (index + 3)); // remove http:// or https:// index = url.indexOf('/'); + if (index == -1) { + log_e("the path of url must not be empty"); + return false; + } String host = url.substring(0, index); url.remove(0, index); // remove host part From 42178b82aeb5983de3ef98b28a1b98cad0ce9b94 Mon Sep 17 00:00:00 2001 From: long_long_float Date: Wed, 8 Sep 2021 23:13:52 +0900 Subject: [PATCH 2/2] Append '/' to an URL with empty path instead of returning an error --- libraries/HTTPClient/src/HTTPClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/HTTPClient/src/HTTPClient.cpp b/libraries/HTTPClient/src/HTTPClient.cpp index a956eaead87..cc0a31e2b6b 100644 --- a/libraries/HTTPClient/src/HTTPClient.cpp +++ b/libraries/HTTPClient/src/HTTPClient.cpp @@ -262,8 +262,8 @@ bool HTTPClient::beginInternal(String url, const char* expectedProtocol) index = url.indexOf('/'); if (index == -1) { - log_e("the path of url must not be empty"); - return false; + index = url.length(); + url += '/'; } String host = url.substring(0, index); url.remove(0, index); // remove host part