mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 07:20:24 +00:00
[web_server] Mask the value of a password text entity, not only its state (#19385)
This commit is contained in:
@@ -1413,8 +1413,11 @@ json::SerializationBuffer<> WebServer::text_json_(text::Text *obj, const std::st
|
||||
json::JsonBuilder builder;
|
||||
JsonObject root = builder.root();
|
||||
|
||||
const char *state = obj->traits.get_mode() == text::TextMode::TEXT_MODE_PASSWORD ? "********" : value.c_str();
|
||||
set_json_icon_state_value(root, obj, "text", state, value.c_str(), start_config);
|
||||
// A password entity shows the mask and prefills the input with nothing, so the secret never
|
||||
// reaches the JSON and the mask cannot be written back as the value
|
||||
const bool password = obj->traits.get_mode() == text::TextMode::TEXT_MODE_PASSWORD;
|
||||
set_json_icon_state_value(root, obj, "text", password ? "********" : value.c_str(), password ? "" : value.c_str(),
|
||||
start_config);
|
||||
root[ESPHOME_F("min_length")] = obj->traits.get_min_length();
|
||||
root[ESPHOME_F("max_length")] = obj->traits.get_max_length();
|
||||
root[ESPHOME_F("pattern")] = obj->traits.get_pattern_c_str();
|
||||
|
||||
Reference in New Issue
Block a user