Home » Date and Time » Date » Bug #1236
bad regexp avoid format date
Details
| Submitted | 2004-04-18 09:46 UTC |
|---|---|
| From | chief at php dot net |
| Assigned | pajoye |
| Status | No Feedback |
| Package | Date |
| PHP Version | Irrelevant |
| OS | n/a |
| Roadmaps | (Not assigned) |
Comments
[2004-04-18 09:46 UTC] chief at php dot net
Description:
------------
I discovered that if you try to create new date with this format:
$date = new Date('2003-07-15 22:53:37+01');
the current regexp doesn't match this.
The correct regexop should be:
preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(Z|[\+\-]\d{2}):?(\d{2})?)?$/i', $date, $regs)
best regards,
Radek
here is a full patch:
Index: Date.php
===================================================================
RCS file: /repository/pear/Date/Date.php,v
retrieving revision 1.27
diff -r1.27 Date.php
147c147
< preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(Z|[\+\-]\d{2}:?\d{2})?)?$/i', $date, $regs)
---
> preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(Z|[\+\-]\d{2}):?(\d{2})?)?$/i', $date, $regs)
165a166,168
> if(isset($regs[9])) {
> $regs[8] += ':'.$regs[9];
> }
[2004-05-12 10:06 UTC] aashley at optimiser dot com
umm sorry if this seems obvious to you, but how is this considered a bug? The ISO8601 standard says that timezone offset must be represented by 4 digits if it is present.
IMHO the bug is actually in whatever code is trying to load a date with that format.
[2004-05-16 11:41 UTC] paj at pearfr dot org
Hello,
Please point me to the RFC related to this format. If there is none I do not see the point to allow this format.
--Pierre