this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

pkg/encoding: add tests that Unmarshal rejects trailing input

json correctly rejects trailing input whether it is valid or invalid,
like encoding/json.Unmarshal does, but yaml does not yet,
as already pointed out in the TODO I added to internal/encoding/yaml.
The following CL will fix the yaml package to do the right thing.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I01b381259ca0251bdb6e46dab60ca943226fe793
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1193241
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+23
+14
pkg/encoding/json/testdata/gen.txtar
··· 42 42 #result: json.Unmarshal(X) 43 43 } 44 44 unmarshal: t1: "1" 45 + unmarshal: { 46 + trailingValid: #"{"a": 1}{"b": 2}"# 47 + trailingInvalid: #"{"a": 1}}invalid json"# 48 + } 45 49 46 50 marshalStream: [string]: X={ 47 51 [...] // input ··· 88 92 ./in.cue:6:10 89 93 ./in.cue:9:27 90 94 json.Validate:1:6 95 + unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 96 + ./in.cue:39:11 97 + unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON: 98 + ./in.cue:39:11 91 99 92 100 Result: 93 101 import "encoding/json" ··· 146 154 t1: { 147 155 "1" 148 156 #result: 1 157 + } 158 + trailingValid: { 159 + #result: _|_ // unmarshal.trailingValid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 160 + } 161 + trailingInvalid: { 162 + #result: _|_ // unmarshal.trailingInvalid.#result: error in call to encoding/json.Unmarshal: json: invalid JSON 149 163 } 150 164 } 151 165 marshalStream: {
+9
pkg/encoding/yaml/testdata/gen.txtar
··· 27 27 null2: yaml.UnmarshalStream('1\n---\n---\n2') 28 28 null2: yaml.UnmarshalStream("1\n---\n---\n2") 29 29 } 30 + 31 + unmarshalTrailingInput: { 32 + valid: yaml.Unmarshal("1\n---\n2") 33 + invalid: yaml.Unmarshal("1\n---\n}invalid yaml") 34 + } 30 35 -- out/yaml -- 31 36 Errors: 32 37 t1: error in call to encoding/yaml.Validate: invalid value 4 (out of bound <3): ··· 75 80 null1: [1, null, 2] 76 81 null2: [1, null, 2] 77 82 } 83 + unmarshalTrailingInput: { 84 + valid: 1 85 + invalid: 1 86 + }