Repository: goccy/go-yaml
Pull request #503 (2024-11-03 05:00:48)

Support empty sequence value
fix https://github.com/goccy/go-yaml/issues/414

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/503?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 75.66%. Comparing base [(`8f8d730`)](https://app.codecov.io/gh/goccy/go-yaml/commit/8f8d7306503489cb9a72fe57e16540be9d386e9b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Masaaki+Goshima) to head [(`f031fb8`)](https://app.codecov.io/gh/goccy/go-yaml/commit/f031fb8b28e9476852294639caeab9d804e052a9?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     #503      +/-   ##
==========================================
- Coverage   76.85%   75.66%   -1.19%     
==========================================
  Files          18       18              
  Lines        6135     6136       +1     
==========================================
- Hits         4715     4643      -72     
- Misses       1112     1181      +69     
- Partials      308      312       +4     
```

</details>

Patch:
diff --git a/parser/parser.go b/parser/parser.go
index de102ee..7a765c8 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -476,9 +476,11 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) {
 	curColumn := tk.Position.Column
 	for tk.Type == token.SequenceEntryType {
 		p.progress(1) // skip sequence token
+		entryTk := tk
 		tk = p.currentToken()
 		if tk == nil {
-			return nil, errors.ErrSyntax("empty sequence value", p.previousToken())
+			sequenceNode.Values = append(sequenceNode.Values, ast.Null(p.createNullToken(entryTk)))
+			break
 		}
 		var comment *ast.CommentGroupNode
 		if tk.Type == token.CommentType {
diff --git a/scanner/scanner.go b/scanner/scanner.go
index c6b5d4c..371bd8a 100644
--- a/scanner/scanner.go
+++ b/scanner/scanner.go
@@ -802,7 +802,7 @@ func (s *Scanner) scanSequence(ctx *Context) bool {
 	}
 
 	nc := ctx.nextChar()
-	if nc != ' ' && !s.isNewLineChar(nc) {
+	if nc != 0 && nc != ' ' && !s.isNewLineChar(nc) {
 		return false
 	}
 


Test patch:
diff --git a/parser/parser_test.go b/parser/parser_test.go
index 6c824a0..6b8b3ae 100644
--- a/parser/parser_test.go
+++ b/parser/parser_test.go
@@ -93,6 +93,7 @@ func TestParser(t *testing.T) {
 		"value: >\n\n",
 		"value: >\nother:",
 		"value: >\n\nother:",
+		"a:\n-",
 	}
 	for _, src := range sources {
 		if _, err := parser.Parse(lexer.Tokenize(src), 0); err != nil {
@@ -974,19 +975,6 @@ a
 		},
 		{
 			`
-a:
-- b: c
-- `,
-			`
-[4:1] empty sequence value
-   2 | a:
-   3 | - b: c
->  4 | -
-       ^
-`,
-		},
-		{
-			`
 a: |invalidopt
   foo
 `,
@@ -1052,7 +1040,7 @@ a: -
 b: -
 `,
 			`
-[3:4] empty sequence value
+[3:4] block sequence entries are not allowed in this context
    2 | a: -
 >  3 | b: -
           ^