Skip to content
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed a bug that caused the `get` function to return `false` instead of an error when doing an invalid lookup.
- Fixed an issue with reading/writing null values in YAML.
- Fixed a nil pointer dereference when reading/writing null YAML documents.

## [v3.3.1] - 2026-02-26

Expand Down
10 changes: 10 additions & 0 deletions parsing/yaml/yaml_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func (j *yamlReader) Read(data []byte) (*model.Value, error) {
}
return nil, err
}
if unmarshalled == nil {
unmarshalled = &yamlValue{
node: nil,
value: model.NewNullValue(),
}
}
res = append(res, unmarshalled)
}

Expand Down Expand Up @@ -73,6 +79,10 @@ func (yv *yamlValue) UnmarshalYAML(value *yaml.Node) error {
return err
}
yv.value = model.NewFloatValue(f)
case "!!null":
yv.value = model.NewNullValue()
case "!!str":
yv.value = model.NewStringValue(value.Value)
default:
yv.value = model.NewStringValue(value.Value)
}
Expand Down
14 changes: 14 additions & 0 deletions parsing/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ name2: *name
`,
out: `name: Tom
name2: Tom
`,
}.run)

t.Run("null read write", rwTestCase{
in: `name: null
`,
out: `name: null
`,
}.run)

t.Run("null document read write", rwTestCase{
in: `null
`,
out: `null
`,
}.run)
}
5 changes: 4 additions & 1 deletion parsing/yaml/yaml_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package yaml

import (
"fmt"

"github.com/tomwright/dasel/v3/model"
"github.com/tomwright/dasel/v3/parsing"
"go.yaml.in/yaml/v4"
Expand Down Expand Up @@ -109,7 +110,9 @@ func (yv *yamlValue) ToNode() (*yaml.Node, error) {
return nil, err
}
case model.TypeNull:
res.Kind = yaml.DocumentNode
res.Kind = yaml.ScalarNode
res.Value = "null"
res.Tag = "!!null"
case model.TypeUnknown:
return nil, fmt.Errorf("unknown type: %s", yv.value.Type())
}
Expand Down
Loading