The decimal's range should not be parsed if parsing fraction digits fails#153
The decimal's range should not be parsed if parsing fraction digits fails#153fredgan wants to merge 1 commit intoopenconfig:masterfrom
Conversation
pkg/yang/types.go
Outdated
|
|
||
| if t.Range != nil { | ||
| // If parsing fractionDigits fails, the ranges should not be parsed | ||
| if t.Range != nil && isDecimal64 && y.FractionDigits != 0 { |
There was a problem hiding this comment.
Could you check that the logic here is right? I think integer types may also have a range that isn't nil, but this resolution of the range is now only implemented for decimal64. If we could add a testcase to ensure that this is properly covered (and demonstrate that we didn't break this) that'd be great.
There was a problem hiding this comment.
You're right, parsing the range of integer types is ignored, I've adjusted the logic and added a testcase.
c0ea443 to
18da630
Compare
| if t.Range != nil { | ||
| // If parsing fraction-digits of type decimal64 fails, the range should not be parsed | ||
| if t.Range != nil && (!isDecimal64 || (isDecimal64 && y.FractionDigits != 0)) { |
There was a problem hiding this comment.
parseRanges already error checks where FractionDigits is 0 (via decimalValueFromString), so I'm wondering if it's actually better to keep the current behaviour and error out, instead of silently allowing parsing to continue?
There was a problem hiding this comment.
Lines 247 to 250 in fd7d014
In fact, the value 0 indicates that the FractionDigits value has already failed to be parsed (via
asRangeInt).
If continue to parse, parserRanges checks the error value 0 as FractionDigits, then reports an unreasonable error msg bad range: invalid number of fraction digits 0: out of range [1..18], and the new testcase also fails because two errors are generated, so I think the value 0 needs to be excluded.
|
I think this is reasonable to add, although I would want to wait until an integration test is added, which should be simple once #188 is merged. If that checks out then LGTM. |
No description provided.