Skip to content

Yaml Path panics with invalid path #595

@gkampitakis

Description

@gkampitakis

Describe the bug

Hey, thanks a lot for creating and maintaining this library. I have started exploring this library as part of extending a snapshot testing library that I have https://github.com/gkampitakis/go-snaps and I want to support YAML snapshots. I was looking into yaml.PathString and when I pass a path with starting with a dot it panics.

Also apart from the README.md I can't find any examples or documentation for the valid yaml path syntax, maybe I missed it.

To Reproduce

package main

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

func main() {
	yaml.PathString(".address")
}


/**
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x104765254]

goroutine 1 [running]:
github.com/goccy/go-yaml.(*PathBuilder).child(...)
*/

Please provide a minimum yaml content that can be reproduced.
We are more than happy to use Go Playground

Expected behavior

I would expect an error if this is invalid path.

Version Variables

  • Go version: 1.23.2
  • go-yaml's Version: v1.15.10

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingyamlpath

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions