Repository: goccy/go-yaml
Pull request #621 (2025-01-17 16:13:38)

Fix flow-mapping-edge-cases
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/621?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 77.36%. Comparing base [(`3b6beba`)](https://app.codecov.io/gh/goccy/go-yaml/commit/3b6beba689623bc516776532797d85e0f1bfd843?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) to head [(`1ab1d1e`)](https://app.codecov.io/gh/goccy/go-yaml/commit/1ab1d1ef7d5c85fbe487acce6c8b9acd605e649b?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     #621      +/-   ##
==========================================
+ Coverage   77.34%   77.36%   +0.01%     
==========================================
  Files          22       22              
  Lines        7880     7885       +5     
==========================================
+ Hits         6095     6100       +5     
  Misses       1368     1368              
  Partials      417      417              
```

</details>

Patch:
diff --git a/scanner/scanner.go b/scanner/scanner.go
index fb068ed..6b8ed09 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -962,6 +962,12 @@ func (s *Scanner) scanMapDelim(ctx *Context) (bool, error) {
 		// like http://
 		return false, nil
 	}
+	if s.startedFlowMapNum > 0 {
+		tk := ctx.lastToken()
+		if tk != nil && tk.Type == token.MappingValueType {
+			return false, nil
+		}
+	}
 
 	if strings.HasPrefix(strings.TrimPrefix(string(ctx.obuf), " "), "\t") && !strings.HasPrefix(string(ctx.buf), "\t") {
 		invalidTk := token.Invalid("tab character cannot use as a map key directly", string(ctx.obuf), s.pos())


Test patch:
diff --git a/yaml_test_suite_test.go b/yaml_test_suite_test.go
index becce12..a64cca8 100644
--- a/yaml_test_suite_test.go
+++ b/yaml_test_suite_test.go
@@ -22,6 +22,7 @@ var failureTestNames = []string{
 	"empty-keys-in-block-and-flow-mapping",             // no json.
 	"empty-lines-at-end-of-document",                   // no json.
 	"flow-mapping-separate-values",                     // no json.
+	"flow-sequence-in-flow-mapping",                    // no json.
 	"implicit-flow-mapping-key-on-one-line",            // no json.
 	"mapping-key-and-flow-sequence-item-anchors",       // no json.
 	"nested-implicit-complex-keys",                     // no json.
@@ -46,10 +47,8 @@ var failureTestNames = []string{
 	"comment-without-whitespace-after-doublequoted-scalar",
 	"construct-binary",
 	"dash-in-flow-sequence",
-	"flow-sequence-in-flow-mapping",
 	"flow-collections-over-many-lines/01",
 	"flow-mapping-colon-on-line-after-key/02",
-	"flow-mapping-edge-cases",
 	"invalid-comment-after-comma",
 	"invalid-comment-after-end-of-flow-sequence",
 	"invalid-comma-in-tag",