diff options
-rw-r--r-- | src/main/scala/spray/json/JsonParser.scala | 6 | ||||
-rw-r--r-- | src/test/scala/spray/json/JsonParserSpec.scala | 13 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/main/scala/spray/json/JsonParser.scala b/src/main/scala/spray/json/JsonParser.scala index cdbedb1..0f371cf 100644 --- a/src/main/scala/spray/json/JsonParser.scala +++ b/src/main/scala/spray/json/JsonParser.scala @@ -39,12 +39,12 @@ class JsonParser(input: ParserInput) { private[this] var jsValue: JsValue = _ def parseJsValue(): JsValue = - parseJsValue(true) + parseJsValue(false) - def parseJsValue(requireEndOfInput: Boolean): JsValue = { + def parseJsValue(allowTrailingInput: Boolean): JsValue = { ws() `value`() - if (requireEndOfInput) + if (!allowTrailingInput) require(EOI) jsValue } diff --git a/src/test/scala/spray/json/JsonParserSpec.scala b/src/test/scala/spray/json/JsonParserSpec.scala index e6a6899..4141007 100644 --- a/src/test/scala/spray/json/JsonParserSpec.scala +++ b/src/test/scala/spray/json/JsonParserSpec.scala @@ -108,10 +108,17 @@ class JsonParserSpec extends Specification { |""".stripMargin } - "parse multiple values when requireEndOfInput is false" in { + "parse multiple values when allowTrailingInput" in { val parser = new JsonParser("""{"key":1}{"key":2}""") - parser.parseJsValue(false) === JsObject("key" -> JsNumber(1)) - parser.parseJsValue(false) === JsObject("key" -> JsNumber(2)) + parser.parseJsValue(true) === JsObject("key" -> JsNumber(1)) + parser.parseJsValue(true) === JsObject("key" -> JsNumber(2)) } + "reject trailing input when !allowTrailingInput" in { + def parser = JsonParser("""{"key":1}x""") + parser must throwA[JsonParser.ParsingException].like { + case e: JsonParser.ParsingException => e.getMessage must contain("expected end-of-input") + } + } + } }
\ No newline at end of file |