arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.18k stars 4.8k forks source link

Script: Invalid IF statements evaluation #19168

Closed peclik closed 1 year ago

peclik commented 1 year ago

PROBLEM DESCRIPTION

The correctness of IF statement evaluation depends on spaces or empty lines before IF statement.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [ ] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
- [x] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:
03:30:18.821 MQT: house/door/rfid/stat/STATUS = {"Status":{"Module":0,"DeviceName":"door-rfid","FriendlyName":["door-rfid"],"Topic":"door/rfid","ButtonTopic":"0","Power":0,"PowerOnState":0,"LedState":1,"LedMask":"FFFF","SaveData":1,"SaveState":0,"SwitchTopic":"0","SwitchMode":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"ButtonRetain":0,"SwitchRetain":0,"SensorRetain":0,"PowerRetain":0,"InfoRetain":0,"StateRetain":0,"StatusRetain":0}}
03:30:18.833 MQT: house/door/rfid/stat/STATUS1 = {"StatusPRM":{"Baudrate":115200,"SerialConfig":"8N1","GroupTopic":"tasmotas","OtaUrl":"http://ota.tasmota.com/tasmota/release/tasmota.bin.gz","RestartReason":"Software/System restart","Uptime":"0T00:54:25","StartupUTC":"2023-07-23T00:35:53","Sleep":50,"CfgHolder":4617,"BootCount":21,"BCResetTime":"2023-07-21T16:50:07","SaveCount":52,"SaveAddress":"F7000"}}
03:30:18.840 MQT: house/door/rfid/stat/STATUS2 = {"StatusFWR":{"Version":"13.0.0(TasmoCompiler-esp8266generic)","BuildDateTime":"2023-07-21T21:52:17","Boot":22,"Core":"2_7_4_9","SDK":"2.2.2-dev(38a443e)","CpuFrequency":80,"Hardware":"ESP8266EX","CR":"354/699"}}
03:30:18.849 MQT: house/door/rfid/stat/STATUS3 = {"StatusLOG":{"SerialLog":2,"WebLog":3,"MqttLog":0,"SysLog":0,"LogHost":"","LogPort":514,"SSId":["ufo.skolni.home",""],"TelePeriod":20,"Resolution":"558180C0","SetOption":["00008008","2805C80001000600003C5A00192800000000","00000080","00006000","00004000","00000000"]}}
03:30:18.861 MQT: house/door/rfid/stat/STATUS4 = {"StatusMEM":{"ProgramSize":540,"Free":460,"Heap":16,"ProgramFlashSize":1024,"FlashSize":4096,"FlashChipId":"1640EF","FlashFrequency":40,"FlashMode":"DOUT","Features":["00000809","8700058D","04080001","02040047","00000080","00000008","00000000","04000000","04000000","00000000"],"Drivers":"1,2,3,9,10,12,62","Sensors":"1,3,5,15,22,53,82","I2CDriver":""}}
03:30:18.873 MQT: house/door/rfid/stat/STATUS5 = {"StatusNET":{"Hostname":"door-rfid","IPAddress":"192.168.50.150","Gateway":"192.168.50.3","Subnetmask":"255.255.255.0","DNSServer1":"192.168.50.3","DNSServer2":"93.99.200.155","Mac":"50:02:91:47:FF:B4","Webserver":2,"HTTP_API":1,"WifiConfig":4,"WifiPower":17.0}}
03:30:18.881 MQT: house/door/rfid/stat/STATUS6 = {"StatusMQT":{"MqttHost":"192.168.50.20","MqttPort":1883,"MqttClientMask":"door-rfid","MqttClient":"door-rfid","MqttUser":"door-rfid","MqttCount":1,"MAX_PACKET_SIZE":1200,"KEEPALIVE":30,"SOCKET_TIMEOUT":4}}
03:30:18.888 MQT: house/door/rfid/stat/STATUS7 = {"StatusTIM":{"UTC":"2023-07-23T01:30:18","Local":"2023-07-23T03:30:18","StartDST":"2023-03-26T02:00:00","EndDST":"2023-10-29T03:00:00","Timezone":99,"Sunrise":"06:12","Sunset":"21:41"}}
03:30:18.896 MQT: house/door/rfid/stat/STATUS10 = {"StatusSNS":{"Time":"2023-07-23T03:30:18"}}
03:30:18.905 MQT: house/door/rfid/stat/STATUS11 = {"StatusSTS":{"Time":"2023-07-23T03:30:18","Uptime":"0T00:54:25","UptimeSec":3265,"Vcc":3.002,"Heap":16,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":24,"MqttCount":1,"POWER":"OFF","Wifi":{"AP":1,"SSId":"xxxxx","BSSId":"CC:2D:E0:11:11:C3","Channel":3,"Mode":"11n","RSSI":78,"Signal":-61,"LinkCount":1,"Downtime":"0T00:00:03"}}}

TO REPRODUCE

Using the following Script code:

>D
code=0
t:x=3

>S
if chg[code]>0 {
  print AAAAAAA

  if 0==0 {
  }
  if 1==1 {
    print BBBBBBB
  }
}

if x==0 {
  x=-1
  code=77
}

In the log, one can see: AAAAAAA BBBBBBBB BBBBBBBB BBBBBBBB

EXPECTED BEHAVIOUR

The program would log: AAAAAAA BBBBBBBB just once.

It will work correctly if either spaces are deleted before if 0==0 or empty line is deleted before the statement.

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

gemu2015 commented 1 year ago

ok, found the bug, will do a pr soon. until that delete empty lines.

peclik commented 1 year ago

It works. Thanks.