openhab / openhab-webui

Web UIs of openHAB
Eclipse Public License 2.0
224 stars 239 forks source link

Syntax validation errors when command mappings contain whitespace #748

Closed mechalas closed 1 year ago

mechalas commented 3 years ago

Using the BasicUI. I need to send a command to a device that has a space or a dash in it (e.g., Yamaha receiver expects to see "Scene 1" or "Scene 2", or "V-AUX"). I can define these mappings in the sitemap using the GUI editor just fine, and they work as expected. This results in the following code:

                Frame icon="receiver" label="Receiver" {
                    Switch icon="switch" label="Power" item=RXA710MainZone_Power
                    Setpoint icon="soundvolume" item=RXA710MainZone_VolumeindB minValue=-80 maxValue=12 step=0.5 label="Adjust Volume"
                    Switch icon="soundvolume_mute" label="Mute" item=RXA710MainZone_Mute
                    Slider icon="soundvolume" label="Volume" item=RXA710MainZone_VolumeindB maxValue=12 minValue=-80 step=0.5
                    Frame label="Input" {
                        Switch mappings=[Scene 1="BD/DVD",Scene 2="Dish TV",Scene 3="Roku",Scene 4="Fire Stick"] icon="receiver" item=RXA710MainZone_Scene label="Main"
                        Switch item=RXA710MainZone_Inputsource mappings=[Bluetooth="Bluetooth",VAUX="Aux",AV1="Nintendo Wii"] label="Other"
                    }
                    Switch label="Sound" item=RXA710MainZone_SurroundProgram mappings=[Straight="Straight Src",7ch Stereo="7ch Stereo",Surround_Decoder="Enh Surround"]
                }

But, the syntax validator flags the whitespace and the dash as errors. E.g.:

Error: Syntax error at line 25 col 47:

                          Switch mappings=[Scene 
                                                ^
Unexpected WS token: " ". Instead, I was expecting to see one of the following:

A equals token based on:
    Mapping → MappingCommand ● %equals MappingLabel
    Mappings →  ● Mapping
    WidgetAttrValue → %lbracket _ ● Mappings _ %rbracket
    WidgetAttr → WidgetAttrName ● WidgetAttrValue
    WidgetAttrs →  ● WidgetAttr
    Widget$ebnf$1 → Widget$ebnf$1 ● WidgetAttrs
    Widget → %nlwidget _ ● Widget$ebnf$1
    Widgets →  ● Widget
    Widget → %lwidget _ Widget$ebnf$3 __ %lbrace __ ● Widgets __ %rbrace
    Widgets → Widgets _ ● Widget
    Widget → %lwidget _ Widget$ebnf$3 __ %lbrace __ ● Widgets __ %rbrace
    Widgets → Widgets _ ● Widget
    Widget → %lwidget _ Widget$ebnf$3 __ %lbrace __ ● Widgets __ %rbrace
    Widgets →  ● Widget
    Widget → %lwidget _ Widget$ebnf$3 __ %lbrace __ ● Widgets __ %rbrace
    Widgets →  ● Widget
    Widget → %lwidget _ Widget$ebnf$3 __ %lbrace __ ● Widgets __ %rbrace
    Widgets →  ● Widget
    Sitemap → %sitemap _ SitemapName __ SitemapLabel __ %lbrace _ ● Widgets _ %rbrace
    Main → _ ● Sitemap _

Since it reports them as errors, you can't save any changes in the integrated Code editor without "fixing" them, but of course "fixing" them changes the commands to include the quotes since commands are treated as literal strings.

runtimeInfo:
  version: 3.0.0
  buildString: Release Build
locale: en_US
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.9.1
  javaVendor: Ubuntu
  osName: Linux
  osVersion: 5.4.0-58-generic
  osArchitecture: amd64
  availableProcessors: 4
  freeMemory: 1083634136
  totalMemory: 2061500416
bindings:
  - airquality
  - amazonechocontrol
  - hdpowerview
  - http
  - hue
  - networkupstools
  - openweathermap
  - oppo
  - samsungtv
  - snmp
  - sonos
  - unifi
  - upnpcontrol
  - weatherunderground
  - yamahareceiver
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: false
    windows: true
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: windows
    pixelRatio: 1
    prefersColorScheme: light
  isSecureContext: false
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: N/A
    hardwareConcurrency: 16
    language: en-US
    languages:
      - en-US
      - en
    onLine: true
    platform: Win32
  screen:
    width: 1920
    height: 1200
    colorDepth: 24
  support:
    touch: false
    pointerEvents: true
    observer: true
    passiveListener: true
    gestures: false
    intersectionObserver: true
  themeOptions:
    dark: light
    filled: true
    pageTransitionAnimation: default
    bars: filled
    homeNavbar: default
    homeBackground: default
    expandableCardAnimation: default
  userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
    like Gecko) Chrome/87.0.4280.88 Safari/537.36
timestamp: 2020-12-29T01:04:39.538Z
cweitkamp commented 3 years ago

Isn't this an UI issue and should go to https://github.com/openhab/openhab-webui/?

I am pretty sure it should be working when you put hyphens around the value too. e.g. with the following syntax:

                        Switch mappings=["Scene 1"="BD/DVD","Scene 2"="Dish TV","Scene 3"="Roku","Scene 4"="Fire Stick"] icon="receiver" item=RXA710MainZone_Scene label="Main"
mechalas commented 3 years ago

That works fine at first, but if you switch back to UI mode and then return to the code view, it strips away the quotes around the values so you are back where you started.

kaikreuzer commented 3 years ago

So it is clearly a bug in the UI (and not in core) as it needs to put quotes around those strings.

Moxified commented 3 years ago

To add to this, I have found the same issue but also with certain special characters such as ">". If you put them in quotes it will validate but they are removed when you return to code later.