From 751aab70a4fd6e4a7afba64fb5ae15a1700db199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Wed, 15 Apr 2026 08:53:27 +0200 Subject: [PATCH] web: fix whitespace-fragile extract_bool_value in request_handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extract_bool_value searched for the literal string "value":true with no tolerance for whitespace after the colon, unlike every other extract_* helper in the same file. If a client sent pretty-printed JSON (space after ':'), the function silently fell through to the integer fallback path. Rewrite to skip whitespace consistently, matching the pattern used by extract_int and extract_float_or. Signed-off-by: Oyvind Harboe Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Øyvind Harboe --- src/web/src/request_handler.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/web/src/request_handler.cpp b/src/web/src/request_handler.cpp index 3c5e671967b..476617a8436 100644 --- a/src/web/src/request_handler.cpp +++ b/src/web/src/request_handler.cpp @@ -363,13 +363,32 @@ static double extract_double_value(const std::string& json) static bool extract_bool_value(const std::string& json) { - if (json.find("\"value\":true") != std::string::npos) { + const std::string needle = "\"value\""; + auto pos = json.find(needle); + if (pos == std::string::npos) { + return false; + } + pos = json.find(':', pos + needle.size()); + if (pos == std::string::npos) { + return false; + } + // Skip whitespace after colon + pos++; + while (pos < json.size() && (json[pos] == ' ' || json[pos] == '\t')) { + pos++; + } + if (pos < json.size() && json[pos] == 't') { return true; } - if (json.find("\"value\":false") != std::string::npos) { + if (pos < json.size() && json[pos] == 'f') { + return false; + } + // Fall back to integer interpretation (0/1) + try { + return std::stoi(json.substr(pos)) != 0; + } catch (...) { return false; } - return extract_int_or(json, "value", 0) != 0; } static void writeColorArray(JsonBuilder& builder,