Skip to content

Commit

Permalink
Allow commas in state of history download (#20088)
Browse files Browse the repository at this point in the history
Allow commas and quotes in state of history download
  • Loading branch information
potelux authored Mar 25, 2024
1 parent 94d5636 commit 869ace7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/panels/history/ha-panel-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,10 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
for (const timeline of this._mungedStateHistory.timeline) {
const entityId = timeline.entity_id;
for (const s of timeline.data) {
csv.push(`${entityId},${s.state},${formatDate(s.last_changed)}\n`);
const safeState = /,|"/.test(s.state)
? `"${s.state.replaceAll('"', '""')}"`
: s.state;
csv.push(`${entityId},${safeState},${formatDate(s.last_changed)}\n`);
}
}
csv[0] = headers.join(",") + "\n";
Expand Down

0 comments on commit 869ace7

Please sign in to comment.