Commit 3a29e1c
Simon Coffey
Support decimal values in cacheDuration parsing
Since the introduction of cacheDuration parsing in 25cbddd we've been
seeing parsing failures for one of our IdPs, whose cacheDuration value
is set to
cacheDuration="PT6H0M0.000S"
This is a valid ISO8601 duration, however the regexp being used for
parsing doesn't provide for the possibility of milliseconds.
The ISO8601 spec[1] supports decimal values for at least some of a
duration's components (S4.4.3.2):
> If necessary for a particular application, the lowest order
> components may have a decimal fraction.
It's not entirely plain which components this might refer to; it could
potentially be any of them (i.e. whichever component happens to be the
smallest in a given duration, which would mean P0.5Y would be valid).
However, applying decimal logic to the nominal components (Y/M/D)
isn't possible in our current implementation, as the DateTime#next_year,
next_month and next_day methods that we're using to construct the
new timestamp only respect integer values. If we parsed decimals but
then ignored them, someone setting a duration of P0.5Y would silently
receive a duration of zero.
Even if we were to try and adjust our implementation to support
fractions in the nominal components, given that all nominal values can
vary in length (months have different lengths, years can be leap years,
days can have leap seconds), the question of what a fractional nominal
component actually means is ill-defined.
This commit therefore adds fractional support to just the H/M/S
components of the duration parsing. To ensure that we actually respect
these values, I've updated our parsed value coercion to always produce
floats.
The spec permits arbitrary decimal precision, and supports both commas
and dots as the decimal separator, which is reflected in the
implementation.
[1] https://www.loc.gov/standards/datetime/iso-tc154-wg5_n0038_iso_wd_8601-1_2016-02-16.pdf1 parent cb9b848 commit 3a29e1c
2 files changed
Lines changed: 18 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 62 | + | |
| 63 | + | |
69 | 64 | | |
70 | 65 | | |
71 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
15 | 23 | | |
16 | 24 | | |
17 | 25 | | |
| |||
0 commit comments