Skip to content

Commit af251bf

Browse files
committed
Strip off trailing whitespace from ztag string before parsing
1 parent a377011 commit af251bf

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

p4ztag_to_json.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.9.1"
3+
version = "0.9.2"
44
author = "Kaushal Modi"
55
description = "Convert Helix Version Control / Perforce (p4) -ztag output to JSON"
66
license = "MIT"

src/p4ztag_to_json.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ proc ztagFileToJson*(filename: string) =
180180
populateJArr(filename.lines)
181181
changeFileExt(filename, "json").writeFile(jArr.pretty)
182182

183-
proc ztagStringToJson*(ztag: string): string =
183+
proc ztagStringToJson*(ztagStr: string): string =
184184
## Convert input ztag string to JSON.
185185
##
186186
runnableExamples:
@@ -202,7 +202,7 @@ proc ztagStringToJson*(ztag: string): string =
202202
]"""
203203
doAssert ztagString.ztagStringToJson() == jsonString
204204
##
205-
populateJArr(ztag.splitLines())
205+
populateJArr(ztagStr.strip().splitLines())
206206
return jArr.pretty()
207207

208208
when isMainModule:
@@ -213,7 +213,7 @@ when isMainModule:
213213
# # prints the converted JSON to the stdout
214214
if not isatty(stdin):
215215
let
216-
stdinData = readAll(stdin).strip()
216+
stdinData = readAll(stdin)
217217
echo stdinData.ztagStringToJson()
218218
else:
219219
let

tests/test1.nim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,7 @@ suite "ztag to json":
6161

6262
test "parse non-ztag data output by p4 just before the ztag stream":
6363
doCheck("ztag_header")
64-
doCheck("ztag_header2")
64+
doCheck("ztag_header2")
65+
66+
test "check that the trialing blank line does not convert to a newline in json string":
67+
doCheck("trailing_blank_line")

tests/trailing_blank_line.ref.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[
2+
{
3+
"depotFile": "//vqp/sykjf/om/WQJEO/datl/dx/b.pjp",
4+
"clientFile": "/gopm/jvjdh/fxppl/pa/kacl/eh/a.lgn",
5+
"haveRev": "none",
6+
"oldAction": "add",
7+
"action": "abandoned"
8+
},
9+
{
10+
"depotFile": "//djr/spdox/qm/DDPWA/pjrr/qm/a.lex",
11+
"clientFile": "/kwdr/hxyhf/aletc/eq/vayl/df/j.bgu",
12+
"haveRev": "none",
13+
"oldAction": "add",
14+
"action": "abandoned"
15+
},
16+
{
17+
"depotFile": "//wgx/jjaot/qy/TTBGD/ebhm/wv/e.kka",
18+
"clientFile": "/dsaf/msbgb/nvdgi/lb/jtro/yf/v.xtv",
19+
"haveRev": "none",
20+
"oldAction": "add",
21+
"action": "abandoned"
22+
}
23+
]

tests/trailing_blank_line.ztag

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
... depotFile //vqp/sykjf/om/WQJEO/datl/dx/b.pjp
2+
... clientFile /gopm/jvjdh/fxppl/pa/kacl/eh/a.lgn
3+
... haveRev none
4+
... oldAction add
5+
... action abandoned
6+
7+
... depotFile //djr/spdox/qm/DDPWA/pjrr/qm/a.lex
8+
... clientFile /kwdr/hxyhf/aletc/eq/vayl/df/j.bgu
9+
... haveRev none
10+
... oldAction add
11+
... action abandoned
12+
13+
... depotFile //wgx/jjaot/qy/TTBGD/ebhm/wv/e.kka
14+
... clientFile /dsaf/msbgb/nvdgi/lb/jtro/yf/v.xtv
15+
... haveRev none
16+
... oldAction add
17+
... action abandoned
18+
19+

0 commit comments

Comments
 (0)