Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix encoding RawMessage that contains leading space #136

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test-json:
go test -cover -race ./json

test-json-bugs:
go test -cover -race ./json/bugs/...
go test -race ./json/bugs/...
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for removing the coverage for this run?

Copy link

@nainya nainya Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got reply over slack: https://twilio.slack.com/archives/G01CPV0P0SE/p1701104274453339?thread_ts=1701100801.803679&cid=G01CPV0P0SE

Coverage is non-applicable, since it only covers non-test code in the same package. Since those bug packages have no non-test code, sampling coverage has no benefit.
I'm pretty sure whomever set up the makefile just copy-pasted the same command to each target


test-json-1.17:
go test -cover -race -tags go1.17 ./json
Expand Down
3 changes: 0 additions & 3 deletions json/bugs/issue11/main.go

This file was deleted.

23 changes: 23 additions & 0 deletions json/bugs/issue136/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"bytes"
"testing"

"github.com/segmentio/encoding/json"
)

func TestIssue136(t *testing.T) {
input := json.RawMessage(` null`)

got, err := json.Marshal(input)
if err != nil {
t.Fatal(err)
}

want := bytes.TrimSpace(input)

if !bytes.Equal(got, want) {
t.Fatalf("Marshal(%q) = %q, want %q", input, got, want)
}
}
4 changes: 0 additions & 4 deletions json/bugs/issue18/main.go

This file was deleted.

3 changes: 0 additions & 3 deletions json/bugs/issue84/main.go

This file was deleted.

1 change: 1 addition & 0 deletions json/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ func (e encoder) encodeRawMessage(b []byte, p unsafe.Pointer) ([]byte, error) {
s = v
} else {
var err error
v = skipSpaces(v) // don't assume that a RawMessage starts with a token.
d := decoder{}
s, _, _, err = d.parseValue(v)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion json/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ func (d decoder) parseValue(b []byte) ([]byte, []byte, Kind, error) {
case '{':
v, b, k, err = d.parseObject(b)
case '[':
k = Array
v, b, k, err = d.parseArray(b)
case '"':
v, b, k, err = d.parseString(b)
Expand Down
Loading