diff options
author | Mark Hatton <mark.hatton@shazam.com> | 2015-04-08 19:12:05 +0100 |
---|---|---|
committer | Mark Hatton <mark.hatton@shazam.com> | 2015-04-09 13:26:14 +0100 |
commit | 828b02eabf4cef1b145918d7c52f3fb457902281 (patch) | |
tree | 92d959ca342f4450947206691ce0634369c2628e /src | |
parent | 9a5f8cd56918173240ebda58fb62de34746057b4 (diff) | |
download | spray-json-828b02eabf4cef1b145918d7c52f3fb457902281.tar.gz spray-json-828b02eabf4cef1b145918d7c52f3fb457902281.tar.bz2 spray-json-828b02eabf4cef1b145918d7c52f3fb457902281.zip |
= Fix multibyte chars at ix 0 of JSON String not being parsed correctly, closes #148
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/spray/json/JsonParser.scala | 2 | ||||
-rw-r--r-- | src/test/scala/spray/json/JsonParserSpec.scala | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/main/scala/spray/json/JsonParser.scala b/src/main/scala/spray/json/JsonParser.scala index 3d61cb4..674d8ea 100644 --- a/src/main/scala/spray/json/JsonParser.scala +++ b/src/main/scala/spray/json/JsonParser.scala @@ -124,7 +124,7 @@ class JsonParser(input: ParserInput) { // http://tools.ietf.org/html/rfc4627#section-2.5 private def `string`(): Unit = { - require('"') + if (cursorChar == '"') cursorChar = input.nextUtf8Char() else fail("'\"'") sb.setLength(0) while (`char`()) cursorChar = input.nextUtf8Char() require('"') diff --git a/src/test/scala/spray/json/JsonParserSpec.scala b/src/test/scala/spray/json/JsonParserSpec.scala index 7d527b1..2fa089f 100644 --- a/src/test/scala/spray/json/JsonParserSpec.scala +++ b/src/test/scala/spray/json/JsonParserSpec.scala @@ -67,6 +67,10 @@ class JsonParserSpec extends Specification { "3-bytes" -> JsString("3-byte UTF-8 chars like ヨ, ᄅ or ᐁ.")) JsonParser(json.prettyPrint.getBytes("UTF-8")) === json } + "parse directly from UTF-8 encoded bytes when string starts with a multi-byte character" in { + val json = JsString("£0.99") + JsonParser(json.prettyPrint.getBytes("UTF-8")) === json + } "be reentrant" in { val largeJsonSource = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/test.json")).mkString List.fill(20)(largeJsonSource).par.map(JsonParser(_)).toList.map { |