diff --git a/decode_test.go b/decode_test.go index 8f55290..e470e64 100644 --- a/decode_test.go +++ b/decode_test.go @@ -2148,7 +2148,7 @@ b: *a t.Parallel() yml := ` a: - "b": 2 + "b" : 2 'c': true ` var v struct { diff --git a/scanner/context.go b/scanner/context.go index c6ec568..09d0a2d 100644 --- a/scanner/context.go +++ b/scanner/context.go @@ -6,6 +6,8 @@ import ( "github.com/goccy/go-yaml/token" ) +const whitespace = ' ' + // Context context at scanning type Context struct { idx int @@ -149,6 +151,18 @@ func (c *Context) currentChar() rune { return rune(0) } +func (c *Context) currentCharWithSkipWhitespace() rune { + idx := c.idx + for c.size > idx { + ch := c.src[idx] + if ch != whitespace { + return ch + } + idx++ + } + return rune(0) +} + func (c *Context) nextChar() rune { if c.size > c.idx+1 { return c.src[c.idx+1] diff --git a/scanner/scanner.go b/scanner/scanner.go index c0072cb..cf58bfb 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -811,9 +811,9 @@ func (s *Scanner) scan(ctx *Context) (pos int) { token, progress := s.scanQuote(ctx, c) ctx.addToken(token) pos += progress - // If the quote is immediately followed by ':', the quote should be treated as a map key. + // If the non-whitespace character immediately following the quote is ':', the quote should be treated as a map key. // Therefore, do not return and continue processing as a normal map key. - if ctx.currentChar() == ':' { + if ctx.currentCharWithSkipWhitespace() == ':' { continue } return