Skip to content

Commit

Permalink
Merge pull request #318 from VirtusLab/issue-313
Browse files Browse the repository at this point in the history
fixed parsing of ellipsis in plain scalars
  • Loading branch information
lbialy authored Jul 20, 2024
2 parents 8ca7ada + 4ba626c commit 8260956
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,12 @@ private class StringTokenizer(str: String) extends Tokenizer {
def readScalar(): String = {
val peeked = in.peek()
peeked match {
case Reader.nullTerminator => sb.result()
case ':' if in.isNextWhitespace => sb.result()
case ':' if in.peekNext() == ',' && ctx.isInFlowCollection => sb.result()
case char if !ctx.isAllowedSpecialCharacter(char) => sb.result()
case _ if isDocumentEnd || isDocumentStart => sb.result()
case ' ' if in.peekNext() == '#' => sb.result()
case Reader.nullTerminator => sb.result()
case ':' if in.isNextWhitespace => sb.result()
case ':' if in.peekNext() == ',' && ctx.isInFlowCollection => sb.result()
case char if !ctx.isAllowedSpecialCharacter(char) => sb.result()
case _ if (isDocumentEnd || isDocumentStart) && ctx.indent == -1 => sb.result()
case ' ' if in.peekNext() == '#' => sb.result()
case _ if in.isNewline =>
ctx.isPlainKeyAllowed = true
if (in.isNextNewline) chompedEmptyLines()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,29 @@ class ParserSuite extends BaseYamlSuite {

assertEquals(yaml.events, Right(expectedEvents))
}

test("issue 313 - parsing elipsis in plain scalar") {
val yaml = """|P:
| e: S...
| c: N
|""".stripMargin

val expectedEvents = List(
StreamStart,
DocumentStart(),
MappingStart(),
Scalar("P"),
MappingStart(),
Scalar("e"),
Scalar("S..."),
Scalar("c"),
Scalar("N"),
MappingEnd,
MappingEnd,
DocumentEnd(),
StreamEnd
)

assertEquals(yaml.events, Right(expectedEvents))
}
}

0 comments on commit 8260956

Please sign in to comment.