Skip to content

Commit

Permalink
Fix parsing colon followed by comma
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Nov 13, 2021
1 parent e82ad39 commit 2393d74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private[yaml] class Scanner(str: String) extends Tokenizer {
val peeked = in.peek()
peeked match
case Some(':') if in.isNextWhitespace => sb.result()
case Some(':') if in.peekNext().exists(_ == ',') => sb.result()
case Some(':') if in.peekNext().exists(_ == ',') && ctx.isInFlowCollection => sb.result()
case Some(char) if !ctx.isAllowedSpecialCharacter(char) => sb.result()
case _ if isDocumentEnd || isDocumentStart => sb.result()
case Some(' ') if in.peekNext() == Some('#') => sb.result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,19 @@ class SequenceSuite extends BaseYamlSuite:
)
assertEquals(yaml.events, Right(expectedEvents))
}

test("colon followed by comma".only) {
val yaml =
"""- :,"""

val expectedEvents = List(
StreamStart,
DocumentStart(),
SequenceStart(),
Scalar(":,"),
SequenceEnd,
DocumentEnd(),
StreamEnd
)
assertEquals(yaml.events, Right(expectedEvents))
}

0 comments on commit 2393d74

Please # to comment.