Skip to content

Commit

Permalink
Merge pull request #25 from shabiel/bug-split-names-json-decoder
Browse files Browse the repository at this point in the history
Names split across multiple lines parsing broke.
  • Loading branch information
shabiel authored Mar 1, 2019
2 parents c36d9c0 + c107849 commit 09043ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/_webjsonDecode.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%webjsonDecode ;SLC/KCM -- Decode JSON;Feb 07, 2019@10:54
%webjsonDecode ;SLC/KCM -- Decode JSON;2019-03-01 10:44 AM
;
DECODE(VVJSON,VVROOT,VVERR) ; Set JSON object into closed array ref VVROOT
;
Expand Down Expand Up @@ -160,7 +160,7 @@
. I $E(@VVJSON@(VVLINE),VVEND-2)="\" S VVIDX=VVEND Q
. I VVEND S VVNAME=VVNAME_$E(@VVJSON@(VVLINE),VVSTART,VVEND-2),VVIDX=VVEND,VVDONE=1
. I 'VVEND S VVNAME=VVNAME_$E(@VVJSON@(VVLINE),VVSTART,$L(@VVJSON@(VVLINE)))
. I 'VVEND!(VVEND>$L(@VVJSON@(VVLINE))) S VVLINE=VVLINE+1,VVIDX=1 I '$D(@VVJSON@(VVLINE)) D ERRX("ORN")
. I 'VVEND!(VVEND>$L(@VVJSON@(VVLINE))) S VVLINE=VVLINE+1,(VVIDX,VVSTART)=1 I '$D(@VVJSON@(VVLINE)) D ERRX("ORN")
; prepend quote if label collates as numeric -- assumes no quotes in label
I VVNAME']]$C(1) S VVNAME=""""""_VVNAME
Q VVNAME
Expand Down
16 changes: 15 additions & 1 deletion src/_webjsonDecodeTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%webjsonDecodeTest ;SLC/KCM -- Unit tests for JSON decoding;Feb 07, 2019@10:55
%webjsonDecodeTest ;SLC/KCM -- Unit tests for JSON decoding;2019-03-01 10:44 AM
;
d EN^%ut($t(+0),3)
quit
Expand Down Expand Up @@ -77,6 +77,20 @@ D ASSERT("urn:va:user:2C0A:1134",$G(Y("ownerCode")))
D ASSERT("SQA,ONE",$G(Y("assignToName")))
D ASSERT("urn:va:user:2C0A:1134",$G(Y("assignToCode")))
Q
SPLITD ;; @TEST multiple line JSON input with key split
n json,y,err
s json(1)="{ ""boo"": ""foo"", ""code"" : ""22-2""}"
d decode^%webjson("json","y","err")
D ASSERT(0,$D(err))
D ASSERT(y("code"),"22-2")
n json,y,err
s json(1)="{ ""boo"": ""foo"", ""c"
s json(2)="ode"": ""22-2""}"
d decode^%webjson("json","y","err")
D ASSERT(0,$D(err))
D ASSERT(y("code"),"22-2")
quit
;
LONG ;; @TEST long document that must be saved across extension nodes
N JSON,Y,ERR,I,LINE,CCNT1,CCNT2
S JSON(1)="{""title"":""long document"",""size"":""rather large"",""document"":"""
Expand Down

0 comments on commit 09043ec

Please sign in to comment.