-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The decimal's range should not be parsed if parsing fraction digits fails #153
base: master
Are you sure you want to change the base?
The decimal's range should not be parsed if parsing fraction digits fails #153
Conversation
pkg/yang/types.go
Outdated
@@ -280,7 +280,8 @@ check: | |||
y.IdentityBase = resolvedBase.Identity | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 247 to 250 in fd7d014
case isDecimal64: | |
// If we are directly of type decimal64 then we must specify | |
// fraction-digits in the range from 1-18. | |
i, err := t.FractionDigits.asRangeInt(1, 18) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Makes sense.
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.