Json.read ignores extra characters
Tested with 0.18.29.
import smithy4s.json.Json
val s = "{}aaaaaaaaaaa"
// s: String = {}aaaaaaaaaaa
Json.readDocument(s)
// res0: Either[PayloadError, Document] = Right({})
Not sure this actually qualifies as a bug.
I think it does, it's not typical for a parser to accept garbage at the end, especially given that there's no nice way to check if anything is left after decoding
Well that's an improvement request then. We have not defined a behaviour, and I'd much prefer it to be generally lenient than overly constrained.
The fact that it's not typical doesn't make it incorrect : it successfully reads a bit of data.
Can we agree that it breaks the principle of least surprise? Besides, it gives you no indication of any unparsed characters, so to extract that sort of information you'd have to do another pass through the input. I'd be OK with this if we returned a (A, Blob /*leftovers*/) but the current shape is simply a footgun
Can we agree that it breaks the principle of least surprise
I'm not even sure we can agree about that here. The that you bumped into this behaviour is more surprising than the fact it doesn't yell at you. The real question is "how did you bump into it ?"
The jsoniter-scala parser has a configuration option to check remaining input: https://github.com/plokhotnyuk/jsoniter-scala/blob/1a06f96de85f53964b63000139c5a35b3191f146/jsoniter-scala-core/shared/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/ReaderConfig.scala#L34
Can we agree that it breaks the principle of least surprise
I'm not even sure we can agree about that here. The that you bumped into this behaviour is more surprising than the fact it doesn't yell at you. The real question is "how did you bump into it ?"
By trying to provoke a decoding failure in one of the ways that usually works 😄 by adding text to a textarea that gets piped to a validator.
Anyhow, if you want to enable that option that Andriy pointed to, I don't mind much.