mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Use inclusive terminology (#1137)
This commit is contained in:
@@ -30,7 +30,7 @@ bool HOT ICACHE_RAM_ATTR ESPOneWire::reset() {
|
||||
|
||||
// Switch into RX mode, letting the pin float
|
||||
this->pin_->pin_mode(INPUT_PULLUP);
|
||||
// after 15µs-60µs wait time, slave pulls low for 60µs-240µs
|
||||
// after 15µs-60µs wait time, responder pulls low for 60µs-240µs
|
||||
// let's have 70µs just in case
|
||||
delayMicroseconds(70);
|
||||
|
||||
|
||||
@@ -280,8 +280,8 @@ def mqtt_publish_json_action_to_code(config, action_id, template_arg, args):
|
||||
|
||||
|
||||
def get_default_topic_for(data, component_type, name, suffix):
|
||||
whitelist = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
|
||||
sanitized_name = ''.join(x for x in name.lower().replace(' ', '_') if x in whitelist)
|
||||
allowlist = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'
|
||||
sanitized_name = ''.join(x for x in name.lower().replace(' ', '_') if x in allowlist)
|
||||
return '{}/{}/{}/{}'.format(data.topic_prefix, component_type,
|
||||
sanitized_name, suffix)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ static const char *TAG = "mqtt.component";
|
||||
void MQTTComponent::set_retain(bool retain) { this->retain_ = retain; }
|
||||
|
||||
std::string MQTTComponent::get_discovery_topic_(const MQTTDiscoveryInfo &discovery_info) const {
|
||||
std::string sanitized_name = sanitize_string_whitelist(App.get_name(), HOSTNAME_CHARACTER_WHITELIST);
|
||||
std::string sanitized_name = sanitize_string_allowlist(App.get_name(), HOSTNAME_CHARACTER_ALLOWLIST);
|
||||
return discovery_info.prefix + "/" + this->component_type() + "/" + sanitized_name + "/" +
|
||||
this->get_default_object_id_() + "/config";
|
||||
}
|
||||
@@ -117,7 +117,7 @@ bool MQTTComponent::is_discovery_enabled() const {
|
||||
}
|
||||
|
||||
std::string MQTTComponent::get_default_object_id_() const {
|
||||
return sanitize_string_whitelist(to_lowercase_underscore(this->friendly_name()), HOSTNAME_CHARACTER_WHITELIST);
|
||||
return sanitize_string_allowlist(to_lowercase_underscore(this->friendly_name()), HOSTNAME_CHARACTER_ALLOWLIST);
|
||||
}
|
||||
|
||||
void MQTTComponent::subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos) {
|
||||
|
||||
@@ -177,7 +177,7 @@ const std::string &Nameable::get_object_id() { return this->object_id_; }
|
||||
bool Nameable::is_internal() const { return this->internal_; }
|
||||
void Nameable::set_internal(bool internal) { this->internal_ = internal; }
|
||||
void Nameable::calc_object_id_() {
|
||||
this->object_id_ = sanitize_string_whitelist(to_lowercase_underscore(this->name_), HOSTNAME_CHARACTER_WHITELIST);
|
||||
this->object_id_ = sanitize_string_allowlist(to_lowercase_underscore(this->name_), HOSTNAME_CHARACTER_ALLOWLIST);
|
||||
// FNV-1 hash
|
||||
this->object_id_hash_ = fnv1_hash(this->object_id_);
|
||||
}
|
||||
|
||||
@@ -85,16 +85,16 @@ std::string to_lowercase_underscore(std::string s) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string sanitize_string_whitelist(const std::string &s, const std::string &whitelist) {
|
||||
std::string sanitize_string_allowlist(const std::string &s, const std::string &allowlist) {
|
||||
std::string out(s);
|
||||
out.erase(std::remove_if(out.begin(), out.end(),
|
||||
[&whitelist](const char &c) { return whitelist.find(c) == std::string::npos; }),
|
||||
[&allowlist](const char &c) { return allowlist.find(c) == std::string::npos; }),
|
||||
out.end());
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string sanitize_hostname(const std::string &hostname) {
|
||||
std::string s = sanitize_string_whitelist(hostname, HOSTNAME_CHARACTER_WHITELIST);
|
||||
std::string s = sanitize_string_allowlist(hostname, HOSTNAME_CHARACTER_ALLOWLIST);
|
||||
return truncate_string(s, 63);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ ParseOnOffState parse_on_off(const char *str, const char *on, const char *off) {
|
||||
return PARSE_NONE;
|
||||
}
|
||||
|
||||
const char *HOSTNAME_CHARACTER_WHITELIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
||||
const char *HOSTNAME_CHARACTER_ALLOWLIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
|
||||
|
||||
uint8_t crc8(uint8_t *data, uint8_t len) {
|
||||
uint8_t crc = 0;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace esphome {
|
||||
|
||||
/// The characters that are allowed in a hostname.
|
||||
extern const char *HOSTNAME_CHARACTER_WHITELIST;
|
||||
extern const char *HOSTNAME_CHARACTER_ALLOWLIST;
|
||||
|
||||
/// Gets the MAC address as a string, this can be used as way to identify this ESP.
|
||||
std::string get_mac_address();
|
||||
@@ -43,7 +43,7 @@ std::string to_string(double val);
|
||||
std::string to_string(long double val);
|
||||
optional<float> parse_float(const std::string &str);
|
||||
|
||||
/// Sanitize the hostname by removing characters that are not in the whitelist and truncating it to 63 chars.
|
||||
/// Sanitize the hostname by removing characters that are not in the allowlist and truncating it to 63 chars.
|
||||
std::string sanitize_hostname(const std::string &hostname);
|
||||
|
||||
/// Truncate a string to a specific length
|
||||
@@ -121,8 +121,8 @@ std::string uint64_to_string(uint64_t num);
|
||||
/// Convert a uint32_t to a hex string
|
||||
std::string uint32_to_string(uint32_t num);
|
||||
|
||||
/// Sanitizes the input string with the whitelist.
|
||||
std::string sanitize_string_whitelist(const std::string &s, const std::string &whitelist);
|
||||
/// Sanitizes the input string with the allowlist.
|
||||
std::string sanitize_string_allowlist(const std::string &s, const std::string &allowlist);
|
||||
|
||||
uint8_t reverse_bits_8(uint8_t x);
|
||||
uint16_t reverse_bits_16(uint16_t x);
|
||||
|
||||
Reference in New Issue
Block a user