Allow DateTime mapping under bStrictObjectTypeChecking when input is …#254
Closed
djairhogeuens wants to merge 1 commit into
Closed
Allow DateTime mapping under bStrictObjectTypeChecking when input is …#254djairhogeuens wants to merge 1 commit into
djairhogeuens wants to merge 1 commit into
Conversation
…a strict ISO 8601 string Closes cweiske#240. bStrictObjectTypeChecking exists to refuse scalar-to-object conversion because PHP constructors that trust their input can be exploited. DateTime, however, is the canonical case where a JSON scalar IS the natural wire form, so users currently have to disable the flag globally to map dates -- which exposes every other class. Add a narrow exemption: when the target class is a \DateTimeInterface subclass AND the value is a strict-shape ISO 8601 / RFC 3339 / date-only string that round-trips through new \DateTimeImmutable() without warnings, fall through to the existing constructor path. Loose strings the DateTime constructor accepts ("now", "+1month", "yesterday", "2pm") are intentionally still rejected -- they would defeat the security intent of the flag. Semantically impossible inputs ("2024-13-40", "2024-02-30") are caught by DateTime::getLastErrors(). Adds tests/DateTimeStrictTypes_Test (13 tests) and a JsonMapperTest_DateTimes fixture covering both the map() and mapArray() fix sites.
Owner
|
AI generated code. I won't look at it; see #253. |
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.
…a strict ISO 8601 string
Closes #240.
bStrictObjectTypeChecking exists to refuse scalar-to-object conversion because PHP constructors that trust their input can be exploited. DateTime, however, is the canonical case where a JSON scalar IS the natural wire form, so users currently have to disable the flag globally to map dates -- which exposes every other class.
Add a narrow exemption: when the target class is a \DateTimeInterface subclass AND the value is a strict-shape ISO 8601 / RFC 3339 / date-only string that round-trips through new \DateTimeImmutable() without warnings, fall through to the existing constructor path.
Loose strings the DateTime constructor accepts ("now", "+1month", "yesterday", "2pm") are intentionally still rejected -- they would defeat the security intent of the flag. Semantically impossible inputs ("2024-13-40", "2024-02-30") are caught by DateTime::getLastErrors().
Adds tests/DateTimeStrictTypes_Test (13 tests) and a JsonMapperTest_DateTimes fixture covering both the map() and mapArray() fix sites.