Skip to content

Commit

Permalink
fix: non string fiels would error with an unsafeHTML error
Browse files Browse the repository at this point in the history
Fix #725
  • Loading branch information
RomRider committed Jul 24, 2023
1 parent 32700c7 commit d65c347
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,7 @@ class ButtonCard extends LitElement {
};
result = html`
${result}
<div id=${key} class="ellipsis" style=${styleMap(customStyle)}>
${(fields[key] as any).type === 'html' ? fields[key] : unsafeHTML(fields[key])}
</div>
<div id=${key} class="ellipsis" style=${styleMap(customStyle)}>${this._unsafeHTMLorNot(fields[key])}</div>
`;
}
});
Expand Down Expand Up @@ -853,6 +851,14 @@ class ButtonCard extends LitElement {
}
}

private _unsafeHTMLorNot(input: any): any {
if (input.strings || input.values) {
return input;
} else {
return unsafeHTML(`${input}`);
}
}

private _gridHtml(
state: HassEntity | undefined,
configState: StateConfig | undefined,
Expand Down Expand Up @@ -880,21 +886,21 @@ class ButtonCard extends LitElement {
${name
? html`
<div id="name" class="ellipsis" style=${styleMap(nameStyleFromConfig)}>
${(name as any).type === 'html' ? name : unsafeHTML(name)}
${this._unsafeHTMLorNot(name)}
</div>
`
: ''}
${stateString
? html`
<div id="state" class="ellipsis" style=${styleMap(stateStyleFromConfig)}>
${(stateString as any).type === 'html' ? stateString : unsafeHTML(stateString)}
${this._unsafeHTMLorNot(stateString)}
</div>
`
: ''}
${label && !lastChangedTemplate
? html`
<div id="label" class="ellipsis" style=${styleMap(labelStyleFromConfig)}>
${(label as any).type === 'html' ? label : unsafeHTML(label)}
${this._unsafeHTMLorNot(label)}
</div>
`
: ''}
Expand Down

0 comments on commit d65c347

Please sign in to comment.