From 52461f10e71ff8329afc158e600a79e3e29ddb21 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Feb 2026 19:06:28 -0600 Subject: [PATCH] Use httpd_req_get_url_query_len instead of strlen for query length The parsed URL already has the query length available via the httpd API. Avoids redundant strlen over the query string. --- esphome/components/web_server_idf/web_server_idf.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/esphome/components/web_server_idf/web_server_idf.cpp b/esphome/components/web_server_idf/web_server_idf.cpp index c335a47023e..1798159e7f7 100644 --- a/esphome/components/web_server_idf/web_server_idf.cpp +++ b/esphome/components/web_server_idf/web_server_idf.cpp @@ -418,18 +418,18 @@ static auto search_query_sources(httpd_req_t *req, const std::string &post_query return result; } } - // Access query string directly from URI — no stack buffer needed. + // Use httpd API for query length, then access string directly from URI. // http_parser identifies components by offset/length without modifying the URI string. // This is the same pattern used by url_to(). + auto len = httpd_req_get_url_query_len(req); + if (len == 0) { + return {}; + } const char *query = strchr(req->uri, '?'); if (query == nullptr) { return {}; } query++; // skip '?' - size_t len = strlen(query); - if (len == 0) { - return {}; - } return func(query, len, name); }