Skip to content

Commit

Permalink
Fix lexer handling of escaped control chars (zio#213)
Browse files Browse the repository at this point in the history
* Fix lexer handling of escaped control chars

* Scalafmt

Co-authored-by: thinkharder <thinkharderdev@users.noreply.github.com>
  • Loading branch information
2 people authored and brbrown25 committed Mar 16, 2021
1 parent c5ba46f commit 2f2d323
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions zio-json/shared/src/main/scala/zio/json/internal/lexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,13 @@ private final class EscapedString(trace: List[JsonError], in: OneCharReader) ext
if (escaped) {
escaped = false
(c: @switch) match {
case '"' | '\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' => c.toInt
case 'u' => nextHex4()
case '"' | '\\' | '/' => c.toInt
case 'b' => '\b'.toInt
case 'f' => '\f'.toInt
case 'n' => '\n'.toInt
case 'r' => '\r'.toInt
case 't' => '\t'.toInt
case 'u' => nextHex4()
case _ =>
throw UnsafeJson(
JsonError.Message(s"invalid '\\${c.toChar}' in string") :: trace
Expand Down
5 changes: 5 additions & 0 deletions zio-json/shared/src/test/scala/zio/json/DecoderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ object DecoderSpec extends DefaultRunnableSpec {

assert(jsonStr.fromJson[Map[String, Int]])(isRight(equalTo(expected)))
},
test("Map with unicode keys") {
val expected = Map(new String(Array('\u0007', '\n')) -> "value")
val jsonStr = JsonEncoder[Map[String, String]].encodeJson(expected, None)
assert(jsonStr.fromJson[Map[String, String]])(isRight(equalTo(expected)))
},
test("zio.Chunk") {
val jsonStr = """["5XL","2XL","XL"]"""
val expected = Chunk("5XL", "2XL", "XL")
Expand Down

0 comments on commit 2f2d323

Please sign in to comment.