diff --git a/scanner/scanner.go b/scanner/scanner.go index e5c7bad..e00669c 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -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) @@ -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:]) diff --git a/yaml_test_suite_test.go b/yaml_test_suite_test.go index 155efd9..0e1020d 100644 --- a/yaml_test_suite_test.go +++ b/yaml_test_suite_test.go @@ -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",