esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

Error setting with web_server setting template_text with special characters #5113

Open afarago opened 9 months ago

afarago commented 9 months ago

The problem

Using the web server interface to update the value of a text template sensor yields error when non-url friendly chars are entered.

Which version of ESPHome has the issue?

2023.11.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.11.2

What platform are you using?

ESP8266

Board

d1_mini

Component causing the issue

web_server

Example YAML snippet

text:
  - platform: template
    name: "Template text"
    optimistic: true
    min_length: 0
    max_length: 100
    mode: text
    set_action:
      then:
        - lambda: |-
            ESP_LOGI("app", "text changed %s", x.c_str());
        - rtttl.play:
            rtttl: !lambda "return x.c_str();"

Anything in the logs that might be useful for us?

https://oi.esphome.io/v2/www.js restAction method sends the text as is instead or urlencoding it.

restAction(r, t) {
        fetch(`${Jt}/${r.domain}/${r.id}/${t}`, {
            method: "POST",
            body: "true"
        }).then(e=>{
            console.log(e)
        }
        )
    }


### Additional information

My test scenario was to augment rtttl player byt ad-hoc strings.

Entering `Cat:d=16,o=6,b=95:32d,32d#,32d,32d#` only yields to `Cat:d=16,o=6,b=95:32d,32d`

Network console shows
http://192.168.0.54/text/template_text/set?value=Cat:d=16,o=6,b=95:32d,32d

Suggestion: apply urlencoding for the string being sent.
(Might be rather relevant for esphome-webserver)
github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.