Skip to content
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
3 changes: 2 additions & 1 deletion parser/shared/src/main/scala/jawn/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ abstract class Parser[J] {
var i = 0
var x = 0
while (i < 4) {
val n = hc(s.charAt(i).toInt)
val c = s.charAt(i).toInt
val n = if (c < hc.length) hc(c) else -1
if (n < 0) die(pos, "expected valid unicode escape")
x = (x << 4) | n
i += 1
Expand Down
21 changes: 21 additions & 0 deletions parser/shared/src/test/scala/jawn/SyntaxCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ class SyntaxCheck extends Properties("SyntaxCheck") with SyntaxCheckPlatform {
}
}

private val nonAsciiUnicodeEscapes: List[String] =
List(qs("\\u00\u00e90"), qs("\\u12\u0100\u0100"), qs("\\u\uff11\uff12\uff13\uff14"))

property("non-ASCII unicode escape fails with ParseException") = Prop.all(nonAsciiUnicodeEscapes.map { s =>
val results = List(
Parser.parseFromString(s)(NullFacade),
Parser.parseFromByteBuffer(ByteBuffer.wrap(s.getBytes("UTF-8")))(NullFacade)
)
Prop.all(results.map {
case Failure(_: ParseException) => Prop.passed
case other => Prop.falsified :| s"expected Failure(ParseException) for $s, got $other"
}: _*)
}: _*)

property("non-ASCII unicode escape fails with ParseException (async)") = Prop.all(nonAsciiUnicodeEscapes.map { s =>
Try(AsyncParser[Unit](AsyncParser.SingleValue).finalAbsorb(s)(NullFacade)) match {
case Success(Left(_)) => Prop.passed
case other => Prop.falsified :| s"expected Left(ParseException) for $s, got $other"
}
}: _*)

private class BoundedStringParser(s: String, md: Int) extends SyncParser[Unit] with CharBasedParser[Unit] {
override protected[this] def maxDepth: Int = md
private[this] var _line = 0
Expand Down