Skip to content

Commit

Permalink
Escape special characters of automation ID in URL (#19790)
Browse files Browse the repository at this point in the history
* Escape special character of automation ID in URL

* Use encodeURIComponent
  • Loading branch information
piitaya authored Feb 28, 2024
1 parent b982884 commit 94f7430
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/panels/config/areas/ha-config-area-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ class HaConfigAreaPage extends LitElement {
<a
href=${ifDefined(
entityState.attributes.id
? `/config/automation/edit/${entityState.attributes.id}`
? `/config/automation/edit/${encodeURIComponent(entityState.attributes.id)}`
: undefined
)}
>
Expand Down
10 changes: 8 additions & 2 deletions src/panels/config/automation/ha-automation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
</ha-list-item>
${stateObj && this._config && this.narrow
? html`<a href="/config/automation/trace/${this._config.id}">
? html`<a
href="/config/automation/trace/${encodeURIComponent(
this._config.id!
)}"
>
<ha-list-item graphic="icon">
${this.hass.localize(
"ui.panel.config.automation.editor.show_trace"
Expand Down Expand Up @@ -563,7 +567,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
if (this._config?.id) {
const result = await this.confirmUnsavedChanged();
if (result) {
navigate(`/config/automation/trace/${this._config.id}`);
navigate(
`/config/automation/trace/${encodeURIComponent(this._config.id)}`
);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/panels/config/automation/ha-automation-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ class HaAutomationPicker extends LitElement {
});
return;
}
navigate(`/config/automation/trace/${automation.attributes.id}`);
navigate(
`/config/automation/trace/${encodeURIComponent(automation.attributes.id)}`
);
}

private async _toggle(automation): Promise<void> {
Expand Down Expand Up @@ -530,9 +532,11 @@ class HaAutomationPicker extends LitElement {
);

if (automation?.attributes.id) {
navigate(`/config/automation/edit/${automation.attributes.id}`);
navigate(
`/config/automation/edit/${encodeURIComponent(automation.attributes.id)}`
);
} else {
navigate(`/config/automation/show/${ev.detail.id}`);
navigate(`/config/automation/show/${encodeURIComponent(ev.detail.id)}`);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/panels/config/automation/ha-automation-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ export class HaAutomationTrace extends LitElement {
? html`
<a
class="trace-link"
href="/config/automation/edit/${stateObj.attributes.id}"
href="/config/automation/edit/${encodeURIComponent(
stateObj.attributes.id
)}"
slot="toolbar-icon"
>
<mwc-button>
Expand Down Expand Up @@ -140,7 +142,9 @@ export class HaAutomationTrace extends LitElement {
? html`
<a
class="trace-link"
href="/config/automation/edit/${stateObj.attributes.id}"
href="/config/automation/edit/${encodeURIComponent(
stateObj.attributes.id
)}"
>
<mwc-list-item graphic="icon">
${this.hass.localize(
Expand Down
2 changes: 1 addition & 1 deletion src/panels/config/devices/ha-config-device-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export class HaConfigDevicePage extends LitElement {
<a
href=${ifDefined(
entityState.attributes.id
? `/config/automation/edit/${entityState.attributes.id}`
? `/config/automation/edit/${encodeURIComponent(entityState.attributes.id)}`
: undefined
)}
>
Expand Down

0 comments on commit 94f7430

Please sign in to comment.