-
-
Notifications
You must be signed in to change notification settings - Fork 59
LL: add class InvalidEncodingException and flag VALIDATE_UTF8_ENCODING #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
b668843
LL: add class InvalidEncodingException and flag VALIDATE_UTF8_ENCODIN…
LLyaudet dd6e82e
JsonParser.php correction Octetss -> Octets
LLyaudet a9c2a52
Keep same copyright as other files, and add author tag in PHPDoc-stri…
LLyaudet b62f4a0
add corrections to warnings detected by phpstan.
LLyaudet dce19ad
Merge branch 'main' into issue_52_check_UTF8_encoding
LLyaudet 4b27710
activate long option --validate-utf8-encodin in bin/jsonlint (remove …
LLyaudet 485836e
move UTF-8 validation into parse.
LLyaudet 086fb2f
improve data for exceptions in validateUTF8Encoding similar to my own…
LLyaudet f69273e
add tests in JsonParserTest.php with files nonvalidutf8.json and val…
LLyaudet 07b84fc
add fast-path for mainly valid-UTF8 files using preg_match.
LLyaudet fbadc85
do not allow octets C0, C1, F5, FF in UTF8 validation.
LLyaudet 4d6fd5c
UTF8 validation must forbid range D800 to DFFF
LLyaudet 04efacd
It should be the last non-UTF-8 correction, F5 to F7 are too high val…
LLyaudet d2a194b
add further tests to check all InvalidEncodingException messages.
LLyaudet 7170180
disable fast path for UTF8-validation since it doesn't check for RFC3…
LLyaudet 38be61d
add PHP issue link explaining why it is buggy.
LLyaudet 728b4eb
correction of my bug on surrogate pairs that were checked in another …
LLyaudet 202ff29
deal with bugs in Unicode support of PHP before 5.4.
LLyaudet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the JSON Lint package. | ||
| * | ||
| * (c) Jordi Boggiano <j.boggiano@seld.be> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Seld\JsonLint; | ||
|
|
||
| /** | ||
| * @author Laurent Lyaudet <laurent.lyaudet@gmail.com> | ||
| */ | ||
| class InvalidEncodingException extends ParsingException | ||
| { | ||
| /** | ||
| * @var array{key: string, line: int} | ||
| */ | ||
| protected $details; | ||
|
|
||
| /** | ||
| * @param string $message | ||
| * @param string $key | ||
| * @phpstan-param array{line: int} $details | ||
|
LLyaudet marked this conversation as resolved.
|
||
| */ | ||
| public function __construct($message, $key, array $details) | ||
| { | ||
| $details['key'] = $key; | ||
| parent::__construct($message, $details); | ||
| } | ||
|
|
||
| /** | ||
| * @return string | ||
| */ | ||
| public function getKey() | ||
| { | ||
| return $this->details['key']; | ||
| } | ||
|
|
||
| /** | ||
| * @phpstan-return array{key: string, line: int} | ||
| */ | ||
| public function getDetails() | ||
| { | ||
| return $this->details; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be private IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, probably no further specialization of this exception will be done in the code.
Since the PR is already merged, I will prepare another PR to address your remarks that are not already dealed with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even if specialization is done, the child class can use the getter if it needs to read it.
Btw, I'm not even sure whether those details are useful. I fail to see what they bring compared to the message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but you can't overwrite the PHPDoc in that case, if you want distinct keys in the details array after specialization.
Noob ;). You always need the strongly typed data instead of a hotchpotch string if you want to do further error handling of the exception and some automatized recovery after failure instead of just printing the message of the exception :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the type of a property in a child class does not respect variance rules anyway.
And I don't see the use case anyway for specializing the class: the library will not use your special child class as it won't know about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you need to talk with @Seldaek about variance rules, because currently it already overrides ParsingException:
I assumed array type hint was enough.
Feel free to propose a PR for "the details" ;).
I will mess up with the tests in the meantime :).