Skip to content

Commit

Permalink
Merge pull request #11 from TravisTX/feat/comment-esc
Browse files Browse the repository at this point in the history
fix issue #10 with commented escape characters
  • Loading branch information
muhammadmuzzammil1998 authored Dec 29, 2020
2 parents e1c384b + 4c3b340 commit 615b091
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions jsonc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ var jsonTest, jsoncTest testsStruct
func init() {
jsonTest = testsStruct{
validBlock: b(`{"foo":"bar foo","true":false,"number":42,"object":{"test":"done"},"array":[1,2,3],"url":"https://github.com","escape":"\"wo//rking"}`),
invalidBlock: b(`{"foo":\"`),
invalidBlock: b(`{"foo":`),
}
jsoncTest = testsStruct{
validBlock: b(`{"foo": /** this is a bloc/k comment */ "bar foo", "true": /* true */ false, "number": 42, "object": { "test": "done" }, "array" : [1, 2, 3], "url" : "https://github.com", "escape":"\"wo//rking" }`),
validBlock: b(`{"foo": /** this is a bloc/k comm\"ent */ "bar foo", "true": /* true */ false, "number": 42, "object": { "test": "done" }, "array" : [1, 2, 3], "url" : "https://github.com", "escape":"\"wo//rking" }`),
invalidBlock: b(`{"foo": /* this is a block comment "bar foo", "true": false, "number": 42, "object": { "test": "done" }, "array" : [1, 2, 3], "url" : "https://github.com", "escape":"\"wo//rking }`),
validSingle: b("{\"foo\": // this is a single line comment\n\"bar foo\", \"true\": false, \"number\": 42, \"object\": { \"test\": \"done\" }, \"array\" : [1, 2, 3], \"url\" : \"https://github.com\", \"escape\":\"\\\"wo//rking\" }"),
validSingle: b("{\"foo\": // this is a single line comm\\\"ent\n\"bar foo\", \"true\": false, \"number\": 42, \"object\": { \"test\": \"done\" }, \"array\" : [1, 2, 3], \"url\" : \"https://github.com\", \"escape\":\"\\\"wo//rking\" }"),
invalidSingle: b(`{"foo": // this is a single line comment "bar foo", "true": false, "number": 42, "object": { "test": "done" }, "array" : [1, 2, 3], "url" : "https://github.com", "escape":"\"wo//rking" }`),
}
}
Expand Down
6 changes: 4 additions & 2 deletions translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ func translate(s []byte) []byte {
comment := &commentData{}
for _, ch := range s {
if ch == ESCAPE || escaped {
j[i] = ch
i++
if !comment.startted {
j[i] = ch
i++
}
escaped = !escaped
continue
}
Expand Down

0 comments on commit 615b091

Please sign in to comment.