Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null string gets encoded to null literal #413

Closed
leononame opened this issue Dec 20, 2023 · 2 comments
Closed

Null string gets encoded to null literal #413

leononame opened this issue Dec 20, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@leononame
Copy link

Describe the bug

When encoding the go string "null", it gets encoded into the yaml value null, which is the null literal, rather than a yaml string.

To Reproduce

package main

import (
	"fmt"

	"github.com/goccy/go-yaml"
)

func main() {
	originalData := map[any]any{"nullString": "null", "nullValue": nil}
	// this prints:
	// map[nullString:null nullValue:<nil>]
	fmt.Printf("%v\n", originalData)

	data, _ := yaml.Marshal(originalData)
	var result map[string]any
	// yaml document:
	// nullString: null
	// nullValue: null

	// but should be:
	// nullString: "null"
	// nullValue: null
	fmt.Println(string(data))

	// after unmarshaling, we get:
	// map[nullString:<nil> nullValue:<nil>]
	yaml.Unmarshal(data, &result)
	fmt.Printf("%v\n", result)
}

Playground Link

Expected behavior

It should encode the value as "null" rather than null. See comment in code snippet above

Version Variables

  • Go version: 1.21.5
  • go-yaml's Version: 1.11.2
@leononame leononame added the bug Something isn't working label Dec 20, 2023
@denieryd
Copy link
Contributor

@leononame hi, i just fixed your issue in this PR - #474

@goccy
Copy link
Owner

goccy commented Nov 6, 2024

This problem has already been fixed with latest release. Thank you @denieryd !

@goccy goccy closed this as completed Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants