Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removeFromRightSpace process at scanner #529

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading