ajv-validator / ajv-validator/ajv-formats
date-time and time formats accept colonless timezone offsets (+0530 should be invalid)
- Vorherrschende Sprache
- TypeScript
- Sterne
- 228
- Forks
- 42
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
## Bug
Both _date-time_ and _time_ formats accept "+0530" (colonless offset) when [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339) requires a colon.
## Root Cause
The regex at src/formats.ts uses `(?::?\d\d)`? which makes the colon optional. This matches +05:30 (valid), +0530 (invalid), and +05 (invalid).
### [RFC 3339 §5.6 ABNF](https://www.rfc-editor.org/rfc/rfc3339#section-5.6)
`time-numoffset = ("+" / "-") time-hour ":" time-minute`
The colon is a mandatory literal not optional.
## Why This Survived Issue #55
The fix for [#55](https://github.com/ajv-validator/ajv-formats/issues/55) correctly changed the T separator but carried forward the :? pattern from the original regex. The offset colon was not in scope for that fix.
## Affected Modes
Both fast and full modes are affected here.
## Note on Appendix A
RFC 3339 Appendix A shows ISO 8601 ABNF where the colon is optional. But Appendix A is informational - the normative production in [§5.6 ](https://www.rfc-editor.org/rfc/rfc3339#section-5.6) requires the colon. If colonless offsets are desired use iso-date-time, not date-time.
## Fix
Replace `(?::?\d\d)?` with `:\d\d`
This removes the optional colon and makes minutes mandatory - matching the RFC 3339 ABNF exactly.
## Test Cases
`"2024-01-15T14:30:00+0530"` → currently passes, should fail
`"14:30:00+0530"` → currently passes, should fail
`"2024-01-15T14:30:00+05:30"` → passes, correct
`"14:30:00+05:30"` → passes, correct
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.