From c2c34d39e7f1f55cef3debe9a29fe4caf588a62a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 27 Mar 2026 15:55:56 -1000 Subject: [PATCH] [text_sensor] Assert size before writing, not after --- esphome/components/text_sensor/filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/text_sensor/filter.h b/esphome/components/text_sensor/filter.h index 41eed5f49b..0366c7fb41 100644 --- a/esphome/components/text_sensor/filter.h +++ b/esphome/components/text_sensor/filter.h @@ -165,11 +165,11 @@ bool map_filter_apply(const Substitution *mappings, size_t count, std::string &v template class MapFilter : public Filter { public: explicit MapFilter(const std::initializer_list &mappings) { + ESPHOME_DEBUG_ASSERT(mappings.size() == N); size_t i = 0; for (const auto &m : mappings) { this->mappings_[i++] = m; } - ESPHOME_DEBUG_ASSERT(i == N); } bool new_value(std::string &value) override { return map_filter_apply(this->mappings_.data(), N, value); }