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 parsing of comment #576

Merged
merged 1 commit into from
Dec 7, 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
31 changes: 17 additions & 14 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,11 @@ func (s *Scanner) scanTag(ctx *Context) bool {
}

func (s *Scanner) scanComment(ctx *Context) bool {
if ctx.existsBuffer() && (ctx.previousChar() != ' ' && ctx.previousChar() != '\t') {
return false
if ctx.existsBuffer() {
c := ctx.previousChar()
if c != ' ' && c != '\t' && !s.isNewLineChar(c) {
return false
}
}

s.addBufferedTokenIfExists(ctx)
Expand All @@ -711,19 +714,19 @@ func (s *Scanner) scanComment(ctx *Context) bool {

for idx, c := range ctx.src[ctx.idx:] {
ctx.addOriginBuf(c)
switch c {
case '\n', '\r':
if ctx.previousChar() == '\\' {
continue
}
value := ctx.source(ctx.idx, ctx.idx+idx)
progress := len([]rune(value))
ctx.addToken(token.Comment(value, string(ctx.obuf), s.pos()))
s.progressColumn(ctx, progress)
s.progressLine(ctx)
ctx.clear()
return true
if !s.isNewLineChar(c) {
continue
}
if ctx.previousChar() == '\\' {
continue
}
value := ctx.source(ctx.idx, ctx.idx+idx)
progress := len([]rune(value))
ctx.addToken(token.Comment(value, string(ctx.obuf), s.pos()))
s.progressColumn(ctx, progress)
s.progressLine(ctx)
ctx.clear()
return true
}
// document ends with comment.
value := string(ctx.src[ctx.idx:])
Expand Down
1 change: 0 additions & 1 deletion yaml_test_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var failureTestNames = []string{
"block-mapping-with-missing-keys", // no json.
"block-scalar-with-more-spaces-than-first-content-line",
"colon-at-the-beginning-of-adjacent-flow-scalar",
"comment-in-flow-sequence-before-comma", // pass yamlv3.
"comment-without-whitespace-after-doublequoted-scalar",
"construct-binary",
"dash-in-flow-sequence",
Expand Down
Loading