diff options
author | Mathias <mathias@spray.io> | 2015-05-06 12:34:01 +0200 |
---|---|---|
committer | Mathias <mathias@spray.io> | 2015-05-06 12:41:50 +0200 |
commit | 629c6ef4b4e795b900d5d870fd5cb282d538f70a (patch) | |
tree | c94b86cc419dab525b6156fe4d6bf45a26a1d001 | |
parent | 5843587ac6472c067aa08347d43f68b78857b053 (diff) | |
download | spray-json-629c6ef4b4e795b900d5d870fd5cb282d538f70a.tar.gz spray-json-629c6ef4b4e795b900d5d870fd5cb282d538f70a.tar.bz2 spray-json-629c6ef4b4e795b900d5d870fd5cb282d538f70a.zip |
Make JsonParser require complete consumption of parsing input, closes #137
-rw-r--r-- | src/main/scala/spray/json/JsonParser.scala | 4 | ||||
-rw-r--r-- | src/test/scala/spray/json/JsonParserSpec.scala | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/main/scala/spray/json/JsonParser.scala b/src/main/scala/spray/json/JsonParser.scala index bed8dbd..855ab21 100644 --- a/src/main/scala/spray/json/JsonParser.scala +++ b/src/main/scala/spray/json/JsonParser.scala @@ -41,6 +41,7 @@ class JsonParser(input: ParserInput) { def parseJsValue(): JsValue = { ws() `value`() + require(EOI) jsValue } @@ -202,7 +203,8 @@ class JsonParser(input: ParserInput) { val c = if (Character.isISOControl(errorChar)) "\\u%04x" format errorChar.toInt else errorChar.toString s"character '$c'" } else "end-of-input" - s"Unexpected $unexpected at input index $cursor (line $lineNr, position $col), expected $target" + val expected = if (target != "'\uFFFF'") target else "end-of-input" + s"Unexpected $unexpected at input index $cursor (line $lineNr, position $col), expected $expected" } val detail = { val sanitizedText = text.map(c ⇒ if (Character.isISOControl(c)) '?' else c) diff --git a/src/test/scala/spray/json/JsonParserSpec.scala b/src/test/scala/spray/json/JsonParserSpec.scala index 2fa089f..2bef24c 100644 --- a/src/test/scala/spray/json/JsonParserSpec.scala +++ b/src/test/scala/spray/json/JsonParserSpec.scala @@ -99,6 +99,12 @@ class JsonParserSpec extends Specification { |{"a} | ^ |""".stripMargin + + errorMessage("""{}x""") === + """Unexpected character 'x' at input index 2 (line 1, position 3), expected end-of-input: + |{}x + | ^ + |""".stripMargin } } }
\ No newline at end of file |