Support multi-byte characters (Unicode)#69
Open
bluedasher13 wants to merge 2 commits intoSeldaek:mainfrom
Open
Support multi-byte characters (Unicode)#69bluedasher13 wants to merge 2 commits intoSeldaek:mainfrom
bluedasher13 wants to merge 2 commits intoSeldaek:mainfrom
Conversation
RAW JSON Data (errorData.json):
```json
{"DAMAGE":"圓圓圓圓圓圓圓"
```
Test Code:
```php
$parser = new \Seld\JsonLint\JsonParser();
$exception = $parser->lint(file_get_contents('errorData.json'));
echo $exception->getMessage();
```
【Before fix】:
Result:
```
Parse error on line 1:
...�圓圓圓圓圓圓"
----------------------^
Expected one of: '}', ','
```
Contains incorrect characters, and fails to `json_encode($message)`:
```php
var_export(json_encode($exception->getMessage()) === false);
var_export(json_last_error_msg() === 'Malformed UTF-8 characters, possibly incorrectly encoded');
```
【After fix】:
Result (after fix):
```
Parse error on line 1:
{"DAMAGE":"圓圓圓圓圓圓圓"
------------------^
Expected one of: '}', ','
```
Not contains incorrect characters, and succeed in `json_encode($message)`:
```php
var_export(json_encode($exception->getMessage()) === '"Parse error on line 1:\\n{\\"DAMAGE\\":\\"\\u5713\\u5713\\u5713\\u5713\\u5713\\u5713\\u5713\\"\\n------------------^\\nExpected one of: \'}\', \',\'"');
var_export(json_last_error_msg() === 'No error');
```
RAW JSON Data (errorData.json):
```json
{"DAMAGE":"圓圓圓圓圓圓圓"
```
Test Code:
```php
$parser = new \Seld\JsonLint\JsonParser();
$exception = $parser->lint(file_get_contents('errorData.json'));
echo $exception->getMessage();
```
【Before fix】:
Result:
```
Parse error on line 1:
...�圓圓圓圓圓圓"
----------------------^
Expected one of: '}', ','
```
Contains incorrect characters, and fails to `json_encode($message)`:
```php
var_export(json_encode($exception->getMessage()) === false);
var_export(json_last_error_msg() === 'Malformed UTF-8 characters, possibly incorrectly encoded');
```
【After fix】:
Result (after fix):
```
Parse error on line 1:
{"DAMAGE":"圓圓圓圓圓圓圓"
------------------^
Expected one of: '}', ','
```
Not contains incorrect characters, and succeed in `json_encode($message)`:
```php
var_export(json_encode($exception->getMessage()) === '"Parse error on line 1:\\n{\\"DAMAGE\\":\\"\\u5713\\u5713\\u5713\\u5713\\u5713\\u5713\\u5713\\"\\n------------------^\\nExpected one of: \'}\', \',\'"');
var_export(json_last_error_msg() === 'No error');
```
Owner
|
Thanks but this changes way too much code for what is needed IMO. I think it should be enough to fix this in And for those 3 functions, it is ok to use |
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.
RAW JSON Data (errorData.json):
{"DAMAGE":"圓圓圓圓圓圓圓"Test Code:
【Before fix】:
Result:
Contains incorrect characters, and fails to
json_encode($message):【After fix】:
Result (after fix):
Not contains incorrect characters, and succeed in
json_encode($message):