ext/date: Fix date error messages for embedded NULL bytes - #23363
Open
arshidkv12 wants to merge 3 commits into
Open
ext/date: Fix date error messages for embedded NULL bytes#23363arshidkv12 wants to merge 3 commits into
arshidkv12 wants to merge 3 commits into
Conversation
NickSdot
reviewed
Aug 19, 2026
Comment on lines
+8
to
+14
| } catch (Error $e) { | ||
| echo $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database |
Contributor
There was a problem hiding this comment.
Suggested change
| } catch (Error $e) { | |
| echo $e->getMessage(), PHP_EOL; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| Error: Unknown or bad format (foo%0bar) at position 0 (f) while unserializing: The timezone could not be found in the database |
Comment on lines
+8
to
+14
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| } catch (ValueError $e) { | |
| echo $e->getMessage(), PHP_EOL; | |
| } | |
| ?> | |
| --EXPECT-- | |
| DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECT-- | |
| ValueError: DatePeriod::createFromISO8601String(): Argument #1 ($specification) must not contain any null bytes | |
Comment on lines
+10
to
+16
| } catch (DateMalformedStringException $e) { | ||
| echo $e->getMessage(), "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| DateTime::modify(): Failed to parse time string (foo%0bar) at position %s |
Contributor
There was a problem hiding this comment.
Suggested change
| } catch (DateMalformedStringException $e) { | |
| echo $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| DateTime::modify(): Failed to parse time string (foo%0bar) at position %s | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| DateMalformedStringException: DateTime::modify(): Failed to parse time string (foo%0bar) at position %s |
Comment on lines
+8
to
+14
| } catch (ValueError $e) { | ||
| echo $e->getMessage(), PHP_EOL; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| } catch (ValueError $e) { | |
| echo $e->getMessage(), PHP_EOL; | |
| } | |
| ?> | |
| --EXPECT-- | |
| date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECT-- | |
| ValueError: date_default_timezone_set(): Argument #1 ($timezoneId) must not contain any null bytes | |
| Stack trace: | ||
| #0 %s(%d): DateInterval->__construct('foo\x00bar') | ||
| #1 {main} | ||
| thrown in %s on line %d |
Contributor
There was a problem hiding this comment.
Suggested change
| thrown in %s on line %d | |
| } catch (Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| ValueError: DateInterval::__construct(): Argument #1 ($duration) must not contain any null bytes |
Or was there a reason for catching DateMalformedIntervalStringException?
Comment on lines
+6
to
+14
| DateInterval::createFromDateString("foo\0bar"); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Uncaught ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes in %s:%d | ||
| Stack trace: | ||
| #0 %s(%d): DateInterval::createFromDateString('foo\x00bar') | ||
| #1 {main} | ||
| thrown in %s on line %d No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| DateInterval::createFromDateString("foo\0bar"); | |
| ?> | |
| --EXPECTF-- | |
| Fatal error: Uncaught ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes in %s:%d | |
| Stack trace: | |
| #0 %s(%d): DateInterval::createFromDateString('foo\x00bar') | |
| #1 {main} | |
| thrown in %s on line %d | |
| try { | |
| DateInterval::createFromDateString("foo\0bar"); | |
| } catch(Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| ValueError: DateInterval::createFromDateString(): Argument #1 ($datetime) must not contain any null bytes | |
Or was there a reason for not catching?
Comment on lines
+6
to
+14
| date_interval_create_from_date_string("foo\0bar"); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Uncaught ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes in %s:%d | ||
| Stack trace: | ||
| #0 %s(%d): date_interval_create_from_date_string('foo\x00bar') | ||
| #1 {main} | ||
| thrown in %s on line %d No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| date_interval_create_from_date_string("foo\0bar"); | |
| ?> | |
| --EXPECTF-- | |
| Fatal error: Uncaught ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes in %s:%d | |
| Stack trace: | |
| #0 %s(%d): date_interval_create_from_date_string('foo\x00bar') | |
| #1 {main} | |
| thrown in %s on line %d | |
| try { | |
| date_interval_create_from_date_string("foo\0bar"); | |
| } catch(Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECTF-- | |
| ValueError: date_interval_create_from_date_string(): Argument #1 ($datetime) must not contain any null bytes | |
Or was there any reason for not catching?
Comment on lines
+6
to
+14
| new DateTimeImmutable("foo\0bar"); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Uncaught ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes in %s:%d | ||
| Stack trace: | ||
| #0 %s(%d): DateTimeImmutable->__construct('foo\x00bar') | ||
| #1 {main} | ||
| thrown in %s on line %d No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| new DateTimeImmutable("foo\0bar"); | |
| ?> | |
| --EXPECTF-- | |
| Fatal error: Uncaught ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes in %s:%d | |
| Stack trace: | |
| #0 %s(%d): DateTimeImmutable->__construct('foo\x00bar') | |
| #1 {main} | |
| thrown in %s on line %d | |
| try { | |
| new DateTimeImmutable("foo\0bar"); | |
| } catch(Throwable $e) { | |
| echo $e::class, ': ', $e->getMessage(), "\n"; | |
| } | |
| ?> | |
| --EXPECT-- | |
| ValueError: DateTimeImmutable::__construct(): Argument #1 ($datetime) must not contain any null bytes | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Created a separate PR: #22997