Skip to content

Commit

Permalink
fixed parsing of ellipsis in plain scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
lbialy committed Jul 17, 2024
1 parent 96e1864 commit 7586d14
Show file tree
Hide file tree
Showing 2 changed files with 32 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 @@ -5,6 +5,7 @@ import org.virtuslab.yaml.internal.load.parse.EventKind._
import org.virtuslab.yaml.internal.load.reader.token.ScalarStyle
import org.virtuslab.yaml.internal.load.reader.token.Token
import org.virtuslab.yaml.internal.load.reader.token.TokenKind.MappingKey
import org.virtuslab.yaml.internal.load.parse.NodeEventMetadata

class ParserSuite extends BaseYamlSuite {

Expand Down Expand Up @@ -123,4 +124,29 @@ class ParserSuite extends BaseYamlSuite {

assertEquals(yaml.asNode.left.map(_.msg), Left(errorMessage))
}

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 7586d14

Please sign in to comment.