From e5ac96d7bca1138d6d8e159c0d1da08a60232f32 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 13 Nov 2024 12:59:11 +0900 Subject: [PATCH 1/2] fix removeFromRightSpace process at scanner --- parser/parser_test.go | 5 +++++ scanner/scanner.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index f9218b7..6bb8568 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -128,6 +128,11 @@ a: !tag a: !tag b: c d: e +`, + ` +a: + b: c + `, } for _, src := range sources { diff --git a/scanner/scanner.go b/scanner/scanner.go index 50e24b1..9bd43ac 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -624,7 +624,7 @@ func (s *Scanner) scanNewLine(ctx *Context, c rune) { // a:[space][space] // b: c removedNum := ctx.removeRightSpaceFromBuf() - if removedNum > 0 { + if !s.isFirstCharAtLine && removedNum > 0 { s.column -= removedNum s.offset -= removedNum if s.savedPos != nil { From e30c2206791ddeb0e5835f030d1b919552e7f2ff Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 13 Nov 2024 13:03:04 +0900 Subject: [PATCH 2/2] remove unnecessary path --- scanner/context.go | 3 +-- scanner/scanner.go | 9 +-------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/scanner/context.go b/scanner/context.go index f6c06e1..7c5517d 100644 --- a/scanner/context.go +++ b/scanner/context.go @@ -198,7 +198,7 @@ func (c *Context) addOriginBuf(r rune) { } } -func (c *Context) removeRightSpaceFromBuf() int { +func (c *Context) removeRightSpaceFromBuf() { trimmedBuf := c.obuf[:c.notSpaceOrgCharPos] buflen := len(trimmedBuf) diff := len(c.obuf) - buflen @@ -206,7 +206,6 @@ func (c *Context) removeRightSpaceFromBuf() int { c.obuf = c.obuf[:buflen] c.buf = c.bufferedSrc() } - return diff } func (c *Context) isDocument() bool { diff --git a/scanner/scanner.go b/scanner/scanner.go index 9bd43ac..f1d2774 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -623,14 +623,7 @@ func (s *Scanner) scanNewLine(ctx *Context, c rune) { // --- // a:[space][space] // b: c - removedNum := ctx.removeRightSpaceFromBuf() - if !s.isFirstCharAtLine && removedNum > 0 { - s.column -= removedNum - s.offset -= removedNum - if s.savedPos != nil { - s.savedPos.Column -= removedNum - } - } + ctx.removeRightSpaceFromBuf() // There is no problem that we ignore CR which followed by LF and normalize it to LF, because of following YAML1.2 spec. // > Line breaks inside scalar content must be normalized by the YAML processor. Each such line break must be parsed into a single line feed character.