Skip to content

Commit

Permalink
Fix removeFromRightSpace process at scanner (#529)
Browse files Browse the repository at this point in the history
* fix removeFromRightSpace process at scanner

* remove unnecessary path
  • Loading branch information
goccy authored Nov 13, 2024
1 parent cb4e1b0 commit cab4364
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
5 changes: 5 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ a: !tag
a: !tag
b: c
d: e
`,
`
a:
b: c
`,
}
for _, src := range sources {
Expand Down
3 changes: 1 addition & 2 deletions scanner/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,14 @@ func (c *Context) addOriginBuf(r rune) {
}
}

func (c *Context) removeRightSpaceFromBuf() int {
func (c *Context) removeRightSpaceFromBuf() {
trimmedBuf := c.obuf[:c.notSpaceOrgCharPos]
buflen := len(trimmedBuf)
diff := len(c.obuf) - buflen
if diff > 0 {
c.obuf = c.obuf[:buflen]
c.buf = c.bufferedSrc()
}
return diff
}

func (c *Context) isDocument() bool {
Expand Down
9 changes: 1 addition & 8 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,14 +623,7 @@ func (s *Scanner) scanNewLine(ctx *Context, c rune) {
// ---
// a:[space][space]
// b: c
removedNum := ctx.removeRightSpaceFromBuf()
if removedNum > 0 {
s.column -= removedNum
s.offset -= removedNum
if s.savedPos != nil {
s.savedPos.Column -= removedNum
}
}
ctx.removeRightSpaceFromBuf()

// There is no problem that we ignore CR which followed by LF and normalize it to LF, because of following YAML1.2 spec.
// > Line breaks inside scalar content must be normalized by the YAML processor. Each such line break must be parsed into a single line feed character.
Expand Down

0 comments on commit cab4364

Please sign in to comment.