Repository: goccy/go-yaml
Pull request #500 (2024-11-02 11:22:02)

Fix folded handling
fix https://github.com/goccy/go-yaml/issues/433

codecov-commenter: :warning: Please install the !['codecov app svg image'](https://github.com/codecov/engineering-team/assets/152432831/e90313f4-9d3a-4b63-8b54-cfe14e7ec20d) to ensure uploads and comments are reliably processed by Codecov.

## [Codecov](https://app.codecov.io/gh/goccy/go-yaml/pull/500?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 76.56%. Comparing base [(`9b2c456`)](https://app.codecov.io/gh/goccy/go-yaml/commit/9b2c4569e2563d5cf2f16785b1fa2cab5e09882e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) to head [(`ae5b969`)](https://app.codecov.io/gh/goccy/go-yaml/commit/ae5b969fae455bd5fc97ba2a0181e9f050408753?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima).

:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #500   +/-   ##
=======================================
  Coverage   76.56%   76.56%           
=======================================
  Files          18       18           
  Lines        6037     6039    +2     
=======================================
+ Hits         4622     4624    +2     
  Misses       1108     1108           
  Partials      307      307           
```

</details>

Patch:
diff --git a/scanner/scanner.go b/scanner/scanner.go
index 4426b14..1b21a46 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()))


Test patch:
diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go
index d36215d..309403f 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) {