Fix timezone parsing regression in FastDateParser #1543
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes timezone parsing regression in FastDateParser that broke backward compatibility in commons-lang 3.5+.
Problem
DateUtils.parseDate with pattern "yyyy-MM-dd'T'HH:mm:ss.SSSZZ" fails to parse timezone offsets without colon (e.g., -0500) in versions 3.5+. This worked in version 3.4.
Example failing code:
// This throws ParseException in 3.5+ but worked in 3.4
DateUtils.parseDate("2019-06-11T15:06:11.716-0500", "yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
Root Cause
The regex pattern for ISO_8601_3_STRATEGY in FastDateParser.java requires a colon between hours and minutes: (?::).
The current regex at line 923:
private static final Strategy ISO_8601_3_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\d{2}(?::)\d{2}))");
Solution
Changed the regex to make colon optional: (?::?). This allows both formats:
Updated regex:
private static final Strategy ISO_8601_3_STRATEGY = new ISO8601TimeZoneStrategy("(Z|(?:[+-]\d{2}(?::?)\d{2}))");
Changes Made
Testing Considerations
References
Checklist
Fixes: LANG-1805