mirror of
https://github.com/esphome/esphome.git
synced 2026-03-01 02:14:19 -07:00
Remove remaining readability-redundant-string-cstr NOLINTs
Use const auto& to bind arg() result directly, avoiding unnecessary std::string intermediate copies. Construct std::string only where needed (lambda capture, setter call).
This commit is contained in:
@@ -2002,11 +2002,11 @@ void WebServer::handle_infrared_request(AsyncWebServerRequest *request, const Ur
|
||||
|
||||
// Parse base64url-encoded raw timings (required)
|
||||
// Base64url is URL-safe: uses A-Za-z0-9-_ (no special characters needing escaping)
|
||||
// .c_str() is required for Arduino framework where arg() returns Arduino String instead of std::string
|
||||
std::string encoded = request->arg(ESPHOME_F("data")).c_str(); // NOLINT(readability-redundant-string-cstr)
|
||||
const auto &data_arg = request->arg(ESPHOME_F("data"));
|
||||
|
||||
// Validate base64url is not empty (also catches missing parameter since arg() returns empty string)
|
||||
if (encoded.empty()) {
|
||||
// Arduino String has isEmpty() not empty(), use length() for cross-platform compatibility
|
||||
if (data_arg.length() == 0) { // NOLINT(readability-container-size-empty)
|
||||
request->send(400, ESPHOME_F("text/plain"), ESPHOME_F("Missing or empty 'data' parameter"));
|
||||
return;
|
||||
}
|
||||
@@ -2015,7 +2015,7 @@ void WebServer::handle_infrared_request(AsyncWebServerRequest *request, const Ur
|
||||
// it outlives the call - set_raw_timings_base64url stores a pointer, so the string
|
||||
// must remain valid until perform() completes.
|
||||
// ESP8266 also needs this because ESPAsyncWebServer callbacks run in "sys" context.
|
||||
this->defer([call, encoded = std::move(encoded)]() mutable {
|
||||
this->defer([call, encoded = std::string(data_arg.c_str(), data_arg.length())]() mutable {
|
||||
call.set_raw_timings_base64url(encoded);
|
||||
call.perform();
|
||||
});
|
||||
|
||||
@@ -543,10 +543,10 @@ class WebServer : public Controller,
|
||||
template<typename T, typename Ret>
|
||||
void parse_string_param_(AsyncWebServerRequest *request, ParamNameType param_name, T &call,
|
||||
Ret (T::*setter)(const std::string &)) {
|
||||
// .c_str() is required for Arduino framework where arg() returns Arduino String instead of std::string
|
||||
std::string value = request->arg(param_name).c_str(); // NOLINT(readability-redundant-string-cstr)
|
||||
if (!value.empty()) {
|
||||
(call.*setter)(value);
|
||||
const auto &value = request->arg(param_name);
|
||||
// Arduino String has isEmpty() not empty(), use length() for cross-platform compatibility
|
||||
if (value.length() > 0) { // NOLINT(readability-container-size-empty)
|
||||
(call.*setter)(std::string(value.c_str(), value.length()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user