Skip to content

Commit

Permalink
fix bug in numberTyping
Browse files Browse the repository at this point in the history
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Oct 21, 2021
1 parent 2a9c1a2 commit c19d304
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ cast_type:
case uint64:
s = "xd" + strconv.FormatUint(typedVal, 10)
case string:
if typedVal[0] == 'x' {
if len(typedVal) > 0 && typedVal[0] == 'x' {
s = "x" + typedVal
}
}
Expand All @@ -367,7 +367,7 @@ func convertNestedJSONNumbers(jsonObj interface{}) (interface{}, error) {
typedJSONObj[i], err = convertNestedJSONNumbers(value)
}
case string:
if typedJSONObj[0] == 'x' {
if len(typedJSONObj) > 0 && typedJSONObj[0] == 'x' {
switch typedJSONObj[1] {
case 'a':
var val int64
Expand Down
8 changes: 8 additions & 0 deletions yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ func TestUnmarshal(t *testing.T) {
"b": float64(333),
},
},
{
encoded: []byte("a: \"\"\nb: \n"),
decodeInto: new(interface{}),
decoded: map[string]interface{}{
"a": "",
"b": nil,
},
},
}

for _, test := range tests {
Expand Down

0 comments on commit c19d304

Please sign in to comment.