diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2018-04-10 17:24:56 +0300 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2018-04-10 17:24:56 +0300 |
| commit | 6bc6304143588d063f5b4cf05ec30443814957e1 (patch) | |
| tree | 9f484e5a23bb720b1109981ba33b3c2f98a21f54 | |
| parent | 6c1197333e41763050d60f3939461bed37c348fd (diff) | |
| download | nimpb-6bc6304143588d063f5b4cf05ec30443814957e1.tar.gz nimpb-6bc6304143588d063f5b4cf05ec30443814957e1.zip | |
Fix integer parsing
| -rw-r--r-- | src/nimpb/json.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/nimpb/json.nim b/src/nimpb/json.nim index 0799364..826569d 100644 --- a/src/nimpb/json.nim +++ b/src/nimpb/json.nim @@ -253,6 +253,11 @@ proc parseInt*[T: int32|int64](node: JsonNode): T = result = T(parseBiggestInt(node.str)) elif node.kind == JInt: result = T(getBiggestInt(node)) + elif node.kind == JFloat: + let f = getFloat(node) + if trunc(f) != f: + raise newException(JsonParseError, "not an integer") + result = T(f) else: raise newException(JsonParseError, "not an integer") @@ -261,6 +266,11 @@ proc parseInt*[T: uint32|uint64](node: JsonNode): T = result = T(parseBiggestUInt(node.str)) elif node.kind == JInt: result = T(getBiggestInt(node)) + elif node.kind == JFloat: + let f = getFloat(node) + if trunc(f) != f: + raise newException(JsonParseError, "not an integer") + result = T(f) else: raise newException(JsonParseError, "not an integer") |
