-
-
Notifications
You must be signed in to change notification settings - Fork 152
Json: workaroud for PHP fatal error #1
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
Conversation
|
What about escape these characters before |
|
This passes the test, but it fails on strings such as |
|
I've improved the fix. But will this really work in all cases? |
|
ping @dg |
|
This replaces all correct NULLs after " with invalid charater, so it leads to „Control character error, possibly incorrectly encoded“. Strange ;-) |
|
Damn. In that case I have no idea how to efficiently prevent the fatal error. |
|
This means "invalid" key |
src/Utils/Json.php
Outdated
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.
Or should I use Strings::match?
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.
Are two nesting levels needed?
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.
Strings::match is not needed, RE is corrent and when you use #[^\\\\]"\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+: (two + added), there will be no chance for backtracking error.
|
👍 I don't like people sending me invalid jsons to my API to make my server throw a fatal error. This should be merged ASAP (I seems finished to me) and backported to 2.1 |
src/Utils/Json.php
Outdated
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.
This is faster '#(?<!\\\\)"\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#'
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.
Nice, you can take the same trick one step further – assuming that " is a lot more common in JSON than \ we get '#(?<=[^\\\\]")\\\\u0000(?:[^"\\\\]|\\\\.)*+"\s*+:#'. Performance on real-world JSON is 820 μs for my original, 157 μs for your improvement and 20 μs for my using \ as base matching character.
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.
👍
c7923a7 to
9c4a291
Compare
Json: workaroud for PHP fatal error
|
👍 nice job guys |
PHP function
json_decodehas a nasty bug which lead to fatal error if key starts with a NULL byte. Simple workaround for this is to passtrueas the second parameter. Any tips how to solve this issue inNette\Utils\Json?This pull contains only failing test for now.