[php-src] Issue #12843: `+` stripped from date strings with parse_url
| From: | spiro-peimbertandreakis | Date: | Thu, 30 Nov 2023 23:11:27 +0000 |
| Subject: | [php-src] Issue #12843: `+` stripped from date strings with parse_url | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-245945@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12843
Author: spiro-peimbertandreakis
### Description
The following code:
```php
<?php
// Valid dates in RFC3339 format
$querystr = 'from_date=2023-03-21T05:00:00+00:00&to_date=2023-11-28T20:40:01+00:00';
$parsed = null;
parse_str($querystr, $parsed);
var_dump($querystr, $parsed);
```
Resulted in this output:
```
string(69) "from_date=2023-03-21T05:00:00+00:00&to_date=2023-11-28T20:40:01+00:00"
array(2) {
["from_date"]=>
string(25) "2023-03-21T05:00:00 00:00"
["to_date"]=>
string(25) "2023-11-28T20:40:01 00:00"
}
```
But I expected this output instead (note the
+ not being stripped):
```
string(69) "from_date=2023-03-21T05:00:00+00:00&to_date=2023-11-28T20:40:01+00:00"
array(2) {
["from_date"]=>
string(25) "2023-03-21T05:00:00+00:00"
["to_date"]=>
string(25) "2023-11-28T20:40:01+00:00"
}
```
The incorrect parsed value causes an error if I try to then use it to create a DateTimeImmutable
like so:
```php
$normal = new DateTimeImmutable($parsed['from_date']);
```
Which throws the following error:
```
Fatal error: Uncaught Exception: Failed to parse time string (2023-03-21T05:00:00 00:00) at position
20 (0): Double time specification
```
### PHP Version
PHP 8.0.10
### Operating System
_No response_