Skip to content

got an unexpected result when a slice contains an invalid string #335

@orisano

Description

@orisano

I got an unexpected result when a slice contains an invalid string

repro:

func TestIssue335(t *testing.T) {
	var v []string
	in := []byte(`["\u","A"]`)
	err := json.Unmarshal(in, &v)
	if err == nil {
		t.Errorf("unexpected success") // unexpected success
	}
	if len(v) != 2 {
		t.Errorf("unexpected result: %q", v) // unexpected result: ["\n"]
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions