1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-02 18:12:20 +01:00

Disallow _ in node name (#1632)

This commit is contained in:
Peter Kuehne
2021-04-08 13:26:01 +01:00
committed by GitHub
parent 2e50e1f506
commit eaf9735eda
6 changed files with 18 additions and 12 deletions

View File

@@ -10,7 +10,8 @@ ESP_PLATFORM_ESP32 = "ESP32"
ESP_PLATFORM_ESP8266 = "ESP8266"
ESP_PLATFORMS = [ESP_PLATFORM_ESP32, ESP_PLATFORM_ESP8266]
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789_-"
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
# Lookup table from ESP32 arduino framework version to latest platformio
# package with that version
# See also https://github.com/platformio/platform-espressif32/releases

View File

@@ -1012,6 +1012,10 @@ jQuery.validator.addMethod("nospaces", (value, element) => {
return value.indexOf(' ') < 0;
}, "Name cannot contain any spaces!");
jQuery.validator.addMethod("nounderscores", (value, element) => {
return value.indexOf('_') < 0;
}, "Name cannot contain underscores!");
jQuery.validator.addMethod("lowercase", (value, element) => {
return value === value.toLowerCase();
}, "Name must be all lower case!");

View File

@@ -359,12 +359,12 @@
<p>
Names must be all <strong>lowercase</strong> and <strong>must not contain any spaces</strong>!
Characters that are allowed are: <code class="inlinecode">a-z</code>,
<code class="inlinecode">0-9</code>, <code class="inlinecode">_</code> and <code class="inlinecode">-</code>.
<code class="inlinecode">0-9</code> and <code class="inlinecode">-</code>.
</p>
<div class="input-field col s12">
<input id="node_name" class="validate" type="text" name="name" data-rule-nospaces="true"
data-rule-lowercase="true" required>
data-rule-lowercase="true" data-rule-nounderscores="true" required>
<label for="node_name">Node Name</label>
</div>

View File

@@ -196,11 +196,11 @@ def wizard(path):
color(
Fore.RED,
f'Oh noes, "{name}" isn\'t a valid name. Names can only '
f"include numbers, lower-case letters, underscores and "
f"hyphens.",
f"include numbers, lower-case letters and hyphens. ",
)
)
name = strip_accents(name).lower().replace(" ", "_")
name = strip_accents(name).lower().replace(" ", "-")
name = strip_accents(name).lower().replace("_", "-")
name = "".join(c for c in name if c in ALLOWED_NAME_CHARS)
safe_print(
'Shall I use "{}" as the name instead?'.format(color(Fore.CYAN, name))