Repository: goccy/go-yaml
Pull request #576 (2024-12-07 06:08:51)

Fix parsing of comment
SSIA

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/576?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) Report
Attention: Patch coverage is `87.50000%` with `2 lines` in your changes missing coverage. Please review.
> Project coverage is 77.48%. Comparing base [(`831423f`)](https://app.codecov.io/gh/goccy/go-yaml/commit/831423f4c18f6b5713426217c8d0f2ba6631d66d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) to head [(`dc341e5`)](https://app.codecov.io/gh/goccy/go-yaml/commit/dc341e5f9eac7e2ca74e44cf1e037956e3724a43?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     #576   +/-   ##
=======================================
  Coverage   77.48%   77.48%           
=======================================
  Files          21       21           
  Lines        7500     7502    +2     
=======================================
+ Hits         5811     5813    +2     
  Misses       1293     1293           
  Partials      396      396           
```

</details>

Patch:
diff --git a/scanner/scanner.go b/scanner/scanner.go
index e5c7bad..e00669c 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -701,8 +701,11 @@ func (s *Scanner) scanTag(ctx *Context) bool {
 }
 
 func (s *Scanner) scanComment(ctx *Context) bool {
-	if ctx.existsBuffer() && (ctx.previousChar() != ' ' && ctx.previousChar() != '\t') {
-		return false
+	if ctx.existsBuffer() {
+		c := ctx.previousChar()
+		if c != ' ' && c != '\t' && !s.isNewLineChar(c) {
+			return false
+		}
 	}
 
 	s.addBufferedTokenIfExists(ctx)
@@ -711,19 +714,19 @@ func (s *Scanner) scanComment(ctx *Context) bool {
 
 	for idx, c := range ctx.src[ctx.idx:] {
 		ctx.addOriginBuf(c)
-		switch c {
-		case '\n', '\r':
-			if ctx.previousChar() == '\\' {
-				continue
-			}
-			value := ctx.source(ctx.idx, ctx.idx+idx)
-			progress := len([]rune(value))
-			ctx.addToken(token.Comment(value, string(ctx.obuf), s.pos()))
-			s.progressColumn(ctx, progress)
-			s.progressLine(ctx)
-			ctx.clear()
-			return true
+		if !s.isNewLineChar(c) {
+			continue
 		}
+		if ctx.previousChar() == '\\' {
+			continue
+		}
+		value := ctx.source(ctx.idx, ctx.idx+idx)
+		progress := len([]rune(value))
+		ctx.addToken(token.Comment(value, string(ctx.obuf), s.pos()))
+		s.progressColumn(ctx, progress)
+		s.progressLine(ctx)
+		ctx.clear()
+		return true
 	}
 	// document ends with comment.
 	value := string(ctx.src[ctx.idx:])


Test patch:
diff --git a/yaml_test_suite_test.go b/yaml_test_suite_test.go
index 155efd9..0e1020d 100644
--- a/yaml_test_suite_test.go
+++ b/yaml_test_suite_test.go
@@ -20,7 +20,6 @@ var failureTestNames = []string{
 	"block-mapping-with-missing-keys",   // no json.
 	"block-scalar-with-more-spaces-than-first-content-line",
 	"colon-at-the-beginning-of-adjacent-flow-scalar",
-	"comment-in-flow-sequence-before-comma", // pass yamlv3.
 	"comment-without-whitespace-after-doublequoted-scalar",
 	"construct-binary",
 	"dash-in-flow-sequence",