isoDuration considers fractional seconds to be invalid
- Dominant language
- JavaScript
- Stars
- 21.2k
- Forks
- 1.5k
- Avg merge
- 4h 57m
- Merged PRs (30d)
- 14
Description
#### Support plan
* *is this issue currently blocking your project?* (yes/no): Yes
* *is this issue affecting a production system?* (yes/no): No
#### Context
* *node version*: v12.19.0
* *module version with issue*: 17.3.0
* *last module version without issue*: unknown
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi
* *any other relevant information*:
#### What are you trying to achieve or the steps to reproduce?
When using the `isoDuration` type a ValidationError is thrown with `must be a valid ISO 8601 duration` when using a decimal value for the Seconds (for example: PT4.4S). Per the standard this should be a valid value:
"The smallest value used may also have a decimal fraction[citation needed], as in "P0.5Y" to indicate half a year. This decimal fraction may be specified with either a comma or a full stop, as in "P0,5Y" or "P0.5Y". "
But it looks like the regex does not allow for it:
`internals.isoDuration = /^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$/;`
```js
const videoDuration = `PT${parseFloat(videoMetaData.duration).toFixed(1)}S`;
await AsyncCheckInDetails.query(trx)
.where({ checkInId: id })
.patch({ videoDuration });
```
#### What was the result you got?
`ValidationError: videoDuration: "videoDuration" must be a valid ISO 8601 duration`
#### What result did you expect?
The Update to be successful.
Contributor guide
Research direction
Start by locating the internals.isoDuration regular expression shown in the report and the validation tests covering ISO 8601 durations. Reproduce the PT4.4S case, then update the relevant behavior and tests so fractional seconds are accepted without breaking existing duration validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100