fix: non string fiels would error with an unsafeHTML error

Fix #725
This commit is contained in:
Jérôme Wiedemann 2023-07-24 14:06:25 +00:00
parent 32700c7311
commit d65c34757a
1 changed files with 12 additions and 6 deletions

View File

@ -623,9 +623,7 @@ class ButtonCard extends LitElement {
}; };
result = html` result = html`
${result} ${result}
<div id=${key} class="ellipsis" style=${styleMap(customStyle)}> <div id=${key} class="ellipsis" style=${styleMap(customStyle)}>${this._unsafeHTMLorNot(fields[key])}</div>
${(fields[key] as any).type === 'html' ? fields[key] : unsafeHTML(fields[key])}
</div>
`; `;
} }
}); });
@ -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( private _gridHtml(
state: HassEntity | undefined, state: HassEntity | undefined,
configState: StateConfig | undefined, configState: StateConfig | undefined,
@ -880,21 +886,21 @@ class ButtonCard extends LitElement {
${name ${name
? html` ? html`
<div id="name" class="ellipsis" style=${styleMap(nameStyleFromConfig)}> <div id="name" class="ellipsis" style=${styleMap(nameStyleFromConfig)}>
${(name as any).type === 'html' ? name : unsafeHTML(name)} ${this._unsafeHTMLorNot(name)}
</div> </div>
` `
: ''} : ''}
${stateString ${stateString
? html` ? html`
<div id="state" class="ellipsis" style=${styleMap(stateStyleFromConfig)}> <div id="state" class="ellipsis" style=${styleMap(stateStyleFromConfig)}>
${(stateString as any).type === 'html' ? stateString : unsafeHTML(stateString)} ${this._unsafeHTMLorNot(stateString)}
</div> </div>
` `
: ''} : ''}
${label && !lastChangedTemplate ${label && !lastChangedTemplate
? html` ? html`
<div id="label" class="ellipsis" style=${styleMap(labelStyleFromConfig)}> <div id="label" class="ellipsis" style=${styleMap(labelStyleFromConfig)}>
${(label as any).type === 'html' ? label : unsafeHTML(label)} ${this._unsafeHTMLorNot(label)}
</div> </div>
` `
: ''} : ''}