corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

error when description is empty string #60

Closed sindhukothe closed 5 years ago

sindhukothe commented 7 years ago

When the description field is empty string e.g. description "" Parser is throwing exception. This seems like a valid syntax, but I am not sure.

sekur commented 7 years ago

Yes, I've noticed that as well. I suppose an empty string is technically valid, but it seems like it defeats the purpose of defining a description statement in the schema if it's not going to contain any meaningful value.

sindhukothe commented 7 years ago

True. But I am not the one writing these yangs :)

sekur commented 7 years ago

What YANG module has this? Let me loop in @llhotka to get his thoughts on dealing with this.

llhotka commented 7 years ago

Empty description should be possible, I will check the parsing rules.

llhotka commented 7 years ago

The parser seems to accept empty descriptions, both single- and double quoted.

sindhukothe commented 7 years ago

Example yang with this: https://github.com/YangModels/yang/blob/master/vendor/cisco/xr/611/Cisco-IOS-XR-ipv4-bgp-oper-sub1.yang

llhotka commented 7 years ago

No problem on the parser side:

$ coffee check_submodule.coffee Cisco-IOS-XR-ipv4-bgp-oper-sub1.yang 
Submodule OK.
sekur commented 7 years ago

Thanks @llhotka for your verification. The issue is on yang-js side, it is enforcing that the argument exists... I'll fix on my end.

sekur commented 7 years ago

@llhotka - the issue is that the parser currently returns an empty string both for when the argument is an empty string and when there is no argument.

coffee> parser = require 'yang-parser'
coffee> parser.parse 'description "";'
YangStatement { prf: '', kw: 'description', arg: '', substmts: [] }
coffee> parser.parse 'description;'
YangStatement { prf: '', kw: 'description', arg: '', substmts: [] }
coffee> parser.parse 'input {}'
YangStatement { prf: '', kw: 'input', arg: '', substmts: [] }
coffee> parser.parse 'input "" {}'
YangStatement { prf: '', kw: 'input', arg: '', substmts: [] }

I was previously treating empty arg string as non-existence which was presenting the issue as described in this ticket. If I allow empty arg string from the yang-parser then I will need a way to differentiate between a legitimate empty arg string vs undefined argument. Can you have the yang-parser return arg: undefined/null if no argument found during parsing?