Skip to content

Commit

Permalink
Merge pull request #138 from goccy/feature/fix-issue128
Browse files Browse the repository at this point in the history
Fix handling of tab characters as unnecessary character
  • Loading branch information
goccy authored Jun 17, 2020
2 parents 0bc342e + 6071770 commit d5fc408
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2048,3 +2048,20 @@ func TestDecoder_LiteralWithNewLine(t *testing.T) {
}
}
}

func TestDecoder_TabCharacterAtRight(t *testing.T) {
yml := `
- a: [2 , 2]
b: [2 , 2]
c: [2 , 2]`
var v []map[string][]int
if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
t.Fatal(err)
}
if len(v) != 1 {
t.Fatalf("failed to unmarshal %+v", v)
}
if len(v[0]) != 3 {
t.Fatalf("failed to unmarshal %+v", v)
}
}
4 changes: 2 additions & 2 deletions scanner/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ func (c *Context) addBuf(r rune) {
return
}
c.buf = append(c.buf, r)
if r != ' ' {
if r != ' ' && r != '\t' {
c.notSpaceCharPos = len(c.buf)
}
}

func (c *Context) addOriginBuf(r rune) {
c.obuf = append(c.obuf, r)
if r != ' ' {
if r != ' ' && r != '\t' {
c.notSpaceOrgCharPos = len(c.obuf)
}
}
Expand Down
2 changes: 1 addition & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (s *Scanner) scanLiteral(ctx *Context, c rune) {
func (s *Scanner) scanLiteralHeader(ctx *Context) (pos int, err error) {
header := ctx.currentChar()
ctx.addOriginBuf(header)
ctx.progress(1) // skip '|' or '<' character
ctx.progress(1) // skip '|' or '>' character
for idx, c := range ctx.src[ctx.idx:] {
pos = idx
ctx.addOriginBuf(c)
Expand Down

0 comments on commit d5fc408

Please sign in to comment.