Allow commas in state of history download (#20088)

Allow commas and quotes in state of history download
This commit is contained in:
potelux 2024-03-24 20:30:08 -05:00 committed by GitHub
parent 94d56367fc
commit 869ace74ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 1 deletions

View File

@ -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";