Pircate / CleanJSON

Swift JSON decoder for Codable
MIT License
292 stars 40 forks source link

Fails on decoding large Double #26

Open VasilyKrainov opened 2 years ago

VasilyKrainov commented 2 years ago

This code makes the exception:

let str = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
let data = str.data(using: .utf8)!
let decoder = CleanJSONDecoder()
do {
  let value = try decoder.decode(Double.self, from: data)
  print("OK = \(value)")
} catch {
  print("Error = \(error)")
}

If you remove one of zeroes in "str" then the decoding will be OK. So the limit is 1e165, after which the decoding fails regardless of Double type can really fit.