Skip to content

Commit

Permalink
Merge pull request #190 from go-vela/master
Browse files Browse the repository at this point in the history
Allow ending document delimiter within tag values
  • Loading branch information
goccy authored Jan 21, 2021
2 parents ab7b2c8 + 31f8c17 commit 7c371c2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
43 changes: 43 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,22 @@ func TestDecoder(t *testing.T) {
"---\n",
(*struct{})(nil),
},
{
"...",
(*struct{})(nil),
},
{
"v: go test ./...",
map[string]string{"v": "go test ./..."},
},
{
"v: echo ---",
map[string]string{"v": "echo ---"},
},
{
"v: |\n hello\n ...\n world\n",
map[string]string{"v": "hello\n...\nworld\n"},
},
{
"a: !!binary gIGC\n",
map[string]string{"a": "\x80\x81\x82"},
Expand Down Expand Up @@ -975,6 +991,33 @@ c:
"c": nil,
},
},
{
`---
a: go test ./...
b:
c:
`,
map[string]interface{}{
"a": "go test ./...",
"b": nil,
"c": nil,
},
},
{
`---
a: |
hello
...
world
b:
c:
`,
map[string]interface{}{
"a": "hello\n...\nworld\n",
"b": nil,
"c": nil,
},
},

// Multi bytes
{
Expand Down
4 changes: 2 additions & 2 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
return
}
case '.':
if s.indentNum == 0 && ctx.repeatNum('.') == 3 {
if s.indentNum == 0 && s.column == 1 && ctx.repeatNum('.') == 3 {
ctx.addToken(token.DocumentEnd(s.pos()))
s.progressColumn(ctx, 3)
pos += 2
Expand All @@ -566,7 +566,7 @@ func (s *Scanner) scan(ctx *Context) (pos int) {
return
}
case '-':
if s.indentNum == 0 && ctx.repeatNum('-') == 3 {
if s.indentNum == 0 && s.column == 1 && ctx.repeatNum('-') == 3 {
s.addBufferedTokenIfExists(ctx)
ctx.addToken(token.DocumentHeader(s.pos()))
s.progressColumn(ctx, 3)
Expand Down

0 comments on commit 7c371c2

Please sign in to comment.