From ae5b969fae455bd5fc97ba2a0181e9f050408753 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 2 Nov 2024 20:21:24 +0900 Subject: [PATCH] fix folded handling --- lexer/lexer_test.go | 35 +++++++++++++++++++++++++++++++++++ scanner/scanner.go | 2 ++ 2 files changed, 37 insertions(+) diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index d36215d5..309403f1 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -1815,6 +1815,41 @@ a: !!binary | }, }, }, + { + YAML: ` +a: > + Text`, + Tokens: token.Tokens{ + { + Type: token.StringType, + CharacterType: token.CharacterTypeMiscellaneous, + Indicator: token.NotIndicator, + Value: "a", + Origin: "\na", + }, + { + Type: token.MappingValueType, + CharacterType: token.CharacterTypeIndicator, + Indicator: token.BlockStructureIndicator, + Value: ":", + Origin: ":", + }, + { + Type: token.FoldedType, + CharacterType: token.CharacterTypeIndicator, + Indicator: token.BlockScalarIndicator, + Value: ">", + Origin: " >\n", + }, + { + Type: token.StringType, + CharacterType: token.CharacterTypeMiscellaneous, + Indicator: token.NotIndicator, + Value: "Text", + Origin: " Text", + }, + }, + }, } for _, test := range tests { t.Run(test.YAML, func(t *testing.T) { diff --git a/scanner/scanner.go b/scanner/scanner.go index 4426b143..1b21a462 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -554,6 +554,8 @@ func (s *Scanner) scanLiteral(ctx *Context, c rune) { if ctx.isEOS() { if ctx.isLiteral { ctx.addBuf(c) + } else if ctx.isFolded && !s.isNewLineChar(c) { + ctx.addBuf(c) } value := ctx.bufferedSrc() ctx.addToken(token.String(string(value), string(ctx.obuf), s.pos()))