Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsafeHTML() called with a non-string value #725

Closed
2 tasks
Mariusthvdb opened this issue Jul 24, 2023 · 15 comments
Closed
2 tasks

unsafeHTML() called with a non-string value #725

Mariusthvdb opened this issue Jul 24, 2023 · 15 comments
Labels

Comments

@Mariusthvdb
Copy link
Contributor

Mariusthvdb commented Jul 24, 2023

Checklist

  • I updated the card to the latest version available
  • I cleared the cache of my browser

Describe the bug
A clear and concise description of what the bug is.

after the latest update to 400 dev5 (might have been earlier in the dev version, but didnt notice) a button using:

custom_fields:
  notification: >
    [[[ return Math.round(states['sensor.pond_buiten_sensor_temperature'].state); ]]]

throws

Scherm­afbeelding 2023-07-24 om 09 31 14

and doesnt show.

Commenting that makes the card appear

Version of the card
Version:
4.0.0.dev-5

To Reproduce
This is the configuration I used:

on another card I just found the same things happens when using

 custom_fields:
   notification: >
     [[[ return entity.attributes.current_position; ]]]

Screenshots
If applicable, add screenshots to help explain your problem.

no card:

Scherm­afbeelding 2023-07-24 om 09 32 45

without the notification field:

Scherm­afbeelding 2023-07-24 om 09 33 01

showing a default state value.

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • Browser [e.g. chrome, safari] Any
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@Mariusthvdb Mariusthvdb added the bug Something isn't working label Jul 24, 2023
@RomRider
Copy link
Collaborator

RomRider commented Jul 24, 2023

Can you try with [[[ return Math.round(states['sensor.pond_buiten_sensor_temperature'].state).toString(); ]]] as it says it needs to be a string ?

@RomRider
Copy link
Collaborator

Ok, I think I found the bug. Odd it didn't trigger before as this code is there forever...

@Mariusthvdb
Copy link
Contributor Author

yes, its odd indeed, as my butto has been there for ever too ;-)

btw, can this be caused by the same thing?:

Scherm­afbeelding 2023-07-24 om 13 07 55

got nowhere to look without anything further

github-actions bot pushed a commit that referenced this issue Jul 24, 2023
## [4.0.0-dev.6](v4.0.0-dev.5...v4.0.0-dev.6) (2023-07-24)

### ⚠ BREAKING CHANGES

* **hacs:** Minimum required HA Version is now 2023.7

### Features

* Support for localization in templates ([5de2dc9](5de2dc9))

### Bug Fixes

* custom fields would sometime throw unsafeHTML errors ([c67e1d5](c67e1d5)), closes [#725](#725)
* **hacs:** minimum HA version 2023.7 ([db3b394](db3b394))
@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.0-dev.6 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@RomRider
Copy link
Collaborator

btw, can this be caused by the same thing?:

Probably, but I don't know for sure

@Mariusthvdb
Copy link
Contributor Author

Mariusthvdb commented Jul 24, 2023

Scherm­afbeelding 2023-07-24 om 13 10 32

so I have a template error, that narrows it down....
just odd there is no originator here in the error

btw the other one was also fixed by using:

custom_fields:
  notification: >
    [[[ return entity.attributes.current_position.toString(); ]]]

but I dont get it, why do we need strings in those notifications? they are numbers and we need numbers...

@Mariusthvdb
Copy link
Contributor Author

I found the template_error in connection.js....

it's not you ;-)
it was me in a card-mod-theme template. sorry about that.

@Mariusthvdb
Copy link
Contributor Author

Mariusthvdb commented Jul 24, 2023

so still seeing this same html errors, but now also on:

name: 1

where indeed the name is the number of a spot. Have quite a few of those, and for ages, so he new update frustrates that now somehow.

I can change it into

name: '1'

which makes it a string. silly really, otoh it does make sense somewhat ?

Scherm­afbeelding 2023-07-24 om 14 50 56

this is still ok:

        name: Terrace - 2

as that obviously isnt a number..

@RomRider
Copy link
Collaborator

I'll look further into that... very strange :)

@RomRider
Copy link
Collaborator

4.0.0-dev7 will fix that, please let me know if you see some other strange behaviors because of the fix.

github-actions bot pushed a commit that referenced this issue Jul 24, 2023
## [4.0.0-dev.7](v4.0.0-dev.6...v4.0.0-dev.7) (2023-07-24)

### Bug Fixes

* non string fiels would error with an unsafeHTML error ([d65c347](d65c347)), closes [#725](#725)
@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.0-dev.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@Mariusthvdb
Copy link
Contributor Author

Mariusthvdb commented Jul 24, 2023

just to conform all issues above are fixed in b7:
no more need for:

  • toString() on those notification custom fields
  • quotes around the numbers on name

so far so good!

@Mariusthvdb
Copy link
Contributor Author

believe we can safely close this? I havent seen it any more since that fix..

@RomRider
Copy link
Collaborator

It's going to close automatically on stable release, no worries

github-actions bot pushed a commit that referenced this issue Jul 29, 2023
## [4.0.0](v3.5.0...v4.0.0) (2023-07-29)

### ⚠ BREAKING CHANGES

* **helpers:** If you were using any of the beta before `4.0.0-dev14`. Please replace all the calls to helper functions with `helpers.xxx` for eg. `helpers.relativeTime(entity.state)` or `helpers.localize(entity)`
* **hacs:** Minimum required HA Version is now 2023.7
* **actions:** Requires HA 2023.4 minimum. Support for the new action format (`target` is also be supported), `service_data` should be renamed to `data` (but it still works with the old format)
* **icons:** This might break your card-mod setup
* this might break some of your color settings

### Features

* **action:** `repeat_limit` for `hold_action` ([73c216f](73c216f)), closes [#564](#564) [#555](#555)
* **actions:** Support for the new action (assist) and all the future ones ([d9c17a4](d9c17a4)), closes [#711](#711) [#685](#685)
* **custom_fields:** Add `do_not_eval` to stop evaluating js templates in an embedded card ([1638cf8](1638cf8))
* **helpers:** all template functions are now available through the `helpers` object ([f22ed69](f22ed69))
* **icons:** replace ha-icon with ha-state-icon to follow new HA's icons per domain automatically ([ab6a3f5](ab6a3f5))
* **templates:** new `relativeTime` function to display a relative time in a template and update it automatically ([965a3d7](965a3d7)), closes [#701](#701)
* **templates:** New date and time format helpers ([9b4fb05](9b4fb05))
* **variables:** A variable can depend on another variable based on their name's alphabetical order ([8cddccb](8cddccb)), closes [#656](#656)
* Force the `numeric_precision` for states which are numbers ([24d75c2](24d75c2))
* new helper functions for date/time in templates ([2b75993](2b75993)), closes [#701](#701)
* Support for localization in templates ([5de2dc9](5de2dc9))

### Bug Fixes

* *_action more-info entity as a template was not evaluated ([02441b2](02441b2)), closes [#734](#734)
* `group_expand` now works even if the entity is not a `group.xxx` ([f192ded](f192ded)), closes [#645](#645)
* Color are now aligned with HA > 2022.12 ([685d55e](685d55e)), closes [#635](#635)
* custom fields would sometime throw unsafeHTML errors ([c67e1d5](c67e1d5)), closes [#725](#725)
* ha-icon (if in custom_fields) size was weird ([a448c8e](a448c8e))
* ha-state-icon CSS selector was wrong ([a1bb39a](a1bb39a))
* icon would be cut with card height defined ([19f8393](19f8393)), closes [#731](#731)
* localization fix ([02dfab3](02dfab3)), closes [#685](#685) [#693](#693)
* lock icon was displaying over more-info dialog ([bf075b0](bf075b0)), closes [#694](#694)
* lock would go out of the button ([0b3e4d3](0b3e4d3))
* non string fiels would error with an unsafeHTML error ([d65c347](d65c347)), closes [#725](#725)
* numerical states would not follow HA's format ([72d7c41](72d7c41)), closes [#662](#662)
* optimize contrast color compute ([35109c3](35109c3))
* relativeTime didn't support to set the first letter uppercase ([f8b9b09](f8b9b09)), closes [#735](#735)
* Some cards with child cards wouldn't be clickable ([9f21c58](9f21c58))
* text/icon contrast when using label-card ([01e199b](01e199b))
* variable which were objects were only evaluated once ([e40bda9](e40bda9))
* **templates:** `variables` was `undefined` if none where provided. ([fad332b](fad332b)), closes [#718](#718)
* tooltip would show over everything ([1bc8f99](1bc8f99))
* **color:** main config `color` was broken ([b93c996](b93c996))
* **hacs:** minimum HA version 2023.7 ([db3b394](db3b394))
* **templates:** don't use the `numeric_precision` from the card config for `localize` in js templates by default ([2cc384f](2cc384f))
@github-actions
Copy link

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants