correct JSON API upper date bound (#10489)

* correct JSON API upper date bound

As reported by @quid-agis. Fixes #10449.

CHANGELOG_BEGIN
CHANGELOG_END

* add tests

* test error messages

* more specific catch
This commit is contained in:
Gary Verhaegen 2021-08-06 14:46:59 +02:00 committed by GitHub
parent a96f3d2687
commit 313110c702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -240,7 +240,7 @@ Represented as an ISO 8601 date rendered using the format
0001-01-01
The dates must be between the bounds specified by Daml-LF and ISO 8601,
[0001-01-01, 9999-99-99].
[0001-01-01, 9999-12-31].
Text
****

View File

@ -136,7 +136,14 @@ class ApiCodecCompressed[Cid](val encodeDecimalAsString: Boolean, val encodeInt6
case Model.DamlLfPrimType.Timestamp => { case JsString(v) =>
V.ValueTimestamp(assertDE(Time.Timestamp fromString v))
}
case Model.DamlLfPrimType.Date => { case JsString(v) => V.ValueDate.fromIso8601(v) }
case Model.DamlLfPrimType.Date => { case JsString(v) =>
try {
V.ValueDate.fromIso8601(v)
} catch {
case _: java.time.format.DateTimeParseException | _: IllegalArgumentException =>
throw DeserializationException(s"Invalid date: $v")
}
}
case Model.DamlLfPrimType.Bool => { case JsBoolean(v) => V.ValueBool(v) }
case Model.DamlLfPrimType.List => { case JsArray(v) =>
V.ValueList(

View File

@ -311,6 +311,8 @@ class ApiCodecCompressedSpec
c("\"Alice\"", VA.party)(Ref.Party assertFromString "Alice"),
c("{}", VA.unit)(()),
c("\"2019-06-18\"", VA.date)(Time.Date assertFromString "2019-06-18"),
c("\"9999-12-31\"", VA.date)(Time.Date assertFromString "9999-12-31"),
c("\"0001-01-01\"", VA.date)(Time.Date assertFromString "0001-01-01"),
c("\"abc\"", VA.text)("abc"),
c("true", VA.bool)(true),
cn("""["1", "2", "3"]""", "[1, 2, 3]", VA.list(VA.int64))(Vector(1, 2, 3)),
@ -345,6 +347,14 @@ class ApiCodecCompressedSpec
("\"1970-01-01T00:00:00\"", VA.timestamp, ""),
("\"1970-01-01T00:00:00+01:00\"", VA.timestamp, ""),
("\"1970-01-01T00:00:00+01:00[Europe/Paris]\"", VA.timestamp, ""),
("\"0000-01-01\"", VA.date, "Invalid date: 0000-01-01"),
("\"9999-99-99\"", VA.date, "Invalid date: 9999-99-99"),
("\"9999-12-32\"", VA.date, "Invalid date: 9999-12-32"),
("\"9999-13-31\"", VA.date, "Invalid date: 9999-13-31"),
("\"10000-01-01\"", VA.date, "Invalid date: 10000-01-01"),
("\"1-01-01\"", VA.date, "Invalid date: 1-01-01"),
("\"0001-02-29\"", VA.date, "Invalid date: 0001-02-29"),
("\"not-a-date\"", VA.date, "Invalid date: not-a-date"),
("""{"a": "b", "c": "d"}""", VA.genMap(VA.text, VA.text), ""),
("\"\"", VA.party, "Daml-LF Party is empty"),
(List.fill(256)('a').mkString("\"", "", "\""), VA.party, "Daml-LF Party is too long"),