mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 05:06:38 +00:00
Don't allow view URL to be a number (#26313)
This commit is contained in:
parent
073ba22233
commit
641e406502
@ -29,6 +29,7 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const VALID_PATH_REGEX = /^[a-zA-Z0-9_-]+$/;
|
const VALID_PATH_REGEX = /^[a-zA-Z0-9_-]+$/;
|
||||||
|
const INTEGER_REGEX = /^[0-9]+$/;
|
||||||
|
|
||||||
@customElement("hui-view-editor")
|
@customElement("hui-view-editor")
|
||||||
export class HuiViewEditor extends LitElement {
|
export class HuiViewEditor extends LitElement {
|
||||||
@ -165,14 +166,21 @@ export class HuiViewEditor extends LitElement {
|
|||||||
delete config.top_margin;
|
delete config.top_margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const slugifyTitle = (title: string | undefined) => {
|
||||||
|
const slug = slugify(title || "", "-");
|
||||||
|
if (INTEGER_REGEX.test(slug)) {
|
||||||
|
return `view-${slug}`;
|
||||||
|
}
|
||||||
|
return slug;
|
||||||
|
};
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.isNew &&
|
this.isNew &&
|
||||||
!this._suggestedPath &&
|
!this._suggestedPath &&
|
||||||
this._config.path === config.path &&
|
this._config.path === config.path &&
|
||||||
(!this._config.path ||
|
(!this._config.path || config.path === slugifyTitle(this._config.title))
|
||||||
config.path === slugify(this._config.title || "", "-"))
|
|
||||||
) {
|
) {
|
||||||
config.path = slugify(config.title || "", "-");
|
config.path = slugifyTitle(config.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
let valid = true;
|
let valid = true;
|
||||||
@ -180,6 +188,9 @@ export class HuiViewEditor extends LitElement {
|
|||||||
if (config.path && !VALID_PATH_REGEX.test(config.path)) {
|
if (config.path && !VALID_PATH_REGEX.test(config.path)) {
|
||||||
valid = false;
|
valid = false;
|
||||||
this._error = { path: "error_invalid_path" };
|
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 });
|
fireEvent(this, "view-config-changed", { valid, config });
|
||||||
|
@ -7035,6 +7035,7 @@
|
|||||||
"saving_failed": "Saving failed",
|
"saving_failed": "Saving failed",
|
||||||
"error_same_url": "You cannot save a view with the same URL as a different existing view.",
|
"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_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"
|
"move_to_dashboard": "Move to dashboard"
|
||||||
},
|
},
|
||||||
"edit_view_header": {
|
"edit_view_header": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user