Skip to content

Commit 1380e15

Browse files
committed
Fix #12, space before optional.
1 parent a5d4af8 commit 1380e15

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/jsony.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ proc parseHook*[T: object|ref object](s: string, i: var int, v: var T) =
341341

342342
proc parseHook*[T](s: string, i: var int, v: var Option[T]) =
343343
## Parse an Option.
344+
eatSpace(s, i)
344345
if i + 3 < s.len and s[i+0] == 'n' and s[i+1] == 'u' and s[i+2] == 'l' and s[i+3] == 'l':
345346
i += 4
346347
return

tests/test_options.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ type Entry = object
3434
color: string
3535

3636
check(Entry())
37+
38+
type
39+
Test = object
40+
key: Option[int]
41+
var test = """{ "key": null }""".fromJson(Test)
42+
doAssert test.key.isNone == true
43+
var test2 = """{ "key": 2 }""".fromJson(Test)
44+
doAssert test2.key.isNone == false
45+
doAssert test2.key.get == 2

0 commit comments

Comments
 (0)