diff --git a/src/panels/lovelace/editor/view-editor/hui-view-editor.ts b/src/panels/lovelace/editor/view-editor/hui-view-editor.ts index 76d0307417..60bc62a5bb 100644 --- a/src/panels/lovelace/editor/view-editor/hui-view-editor.ts +++ b/src/panels/lovelace/editor/view-editor/hui-view-editor.ts @@ -29,6 +29,7 @@ declare global { } const VALID_PATH_REGEX = /^[a-zA-Z0-9_-]+$/; +const INTEGER_REGEX = /^[0-9]+$/; @customElement("hui-view-editor") export class HuiViewEditor extends LitElement { @@ -165,14 +166,21 @@ export class HuiViewEditor extends LitElement { delete config.top_margin; } + const slugifyTitle = (title: string | undefined) => { + const slug = slugify(title || "", "-"); + if (INTEGER_REGEX.test(slug)) { + return `view-${slug}`; + } + return slug; + }; + if ( this.isNew && !this._suggestedPath && this._config.path === config.path && - (!this._config.path || - config.path === slugify(this._config.title || "", "-")) + (!this._config.path || config.path === slugifyTitle(this._config.title)) ) { - config.path = slugify(config.title || "", "-"); + config.path = slugifyTitle(config.title); } let valid = true; @@ -180,6 +188,9 @@ export class HuiViewEditor extends LitElement { if (config.path && !VALID_PATH_REGEX.test(config.path)) { valid = false; this._error = { path: "error_invalid_path" }; + } else if (config.path && INTEGER_REGEX.test(config.path)) { + valid = false; + this._error = { path: "error_number" }; } fireEvent(this, "view-config-changed", { valid, config }); diff --git a/src/translations/en.json b/src/translations/en.json index b9c199d8f9..87b55f098e 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -7035,6 +7035,7 @@ "saving_failed": "Saving failed", "error_same_url": "You cannot save a view with the same URL as a different existing view.", "error_invalid_path": "URL contains invalid/reserved characters. Please enter a simple string only for the path of this view.", + "error_number": "URL may not be a number.", "move_to_dashboard": "Move to dashboard" }, "edit_view_header": {