Skip to content

Commit 291009f

Browse files
author
jennybuckley
committed
Allow null scalars
1 parent 5bd90b3 commit 291009f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

typed/helpers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ func (ef errorFormatter) validateScalar(t schema.Scalar, v *value.Value, prefix
129129
if v == nil {
130130
return nil
131131
}
132+
if v.Null {
133+
return nil
134+
}
132135
switch t {
133136
case schema.Numeric:
134137
if v.FloatValue == nil && v.IntValue == nil {

typed/validate_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ var validationCases = []validationTestCase{{
5353
`{"key":"foo"}`,
5454
`{"key":"foo","value":true}`,
5555
`{"key":"foo","value":true}`,
56+
`{"key":null}`,
5657
},
5758
invalidObjects: []typed.YAMLObject{
5859
`{"key":true,"value":1}`,
5960
`{"key":1,"value":{}}`,
6061
`{"key":false,"value":null}`,
61-
`{"key":null}`,
6262
`{"key":[1, 2]}`,
6363
`{"key":{"foo":true}}`,
6464
},
@@ -98,28 +98,28 @@ var validationCases = []validationTestCase{{
9898
elementRelationship: associative
9999
`,
100100
validObjects: []typed.YAMLObject{
101+
`{"numeric":null}`,
101102
`{"numeric":1}`,
102103
`{"numeric":3.14159}`,
104+
`{"string":null}`,
103105
`{"string":"aoeu"}`,
106+
`{"bool":null}`,
104107
`{"bool":true}`,
105108
`{"bool":false}`,
106109
`{"setStr":["a","b","c"]}`,
107110
`{"setBool":[true,false]}`,
108111
`{"setNumeric":[1,2,3,3.14159]}`,
109112
},
110113
invalidObjects: []typed.YAMLObject{
111-
`{"numeric":null}`,
112114
`{"numeric":["foo"]}`,
113115
`{"numeric":{"a":1}}`,
114116
`{"numeric":"foo"}`,
115117
`{"numeric":true}`,
116-
`{"string":null}`,
117118
`{"string":1}`,
118119
`{"string":3.5}`,
119120
`{"string":true}`,
120121
`{"string":{"a":1}}`,
121122
`{"string":["foo"]}`,
122-
`{"bool":null}`,
123123
`{"bool":1}`,
124124
`{"bool":3.5}`,
125125
`{"bool":"aoeu"}`,

0 commit comments

Comments
 (0)