json: Fix issue converting null yaml into json#2706
Merged
htuch merged 2 commits intoenvoyproxy:masterfrom Mar 6, 2018
Merged
Conversation
When envoy reads an empty yaml file it parses it as a null Field which blows up due to the conversion code not handling this case. This change fixes this by treating a null Field as a null json value. Signed-off-by: Snow Pettersen <snowp@squareup.com>
mattklein123
reviewed
Mar 4, 2018
Member
mattklein123
left a comment
There was a problem hiding this comment.
Awesome, thanks. Small nit if you feel like it.
| } | ||
|
|
||
| TEST(JsonLoaderTest, YamlAsJsonString) { | ||
| { |
Member
There was a problem hiding this comment.
nit if you feel like it: I would remove brace at 449/452. They are not needed as this is the only thing that happens in this test.
Signed-off-by: Snow Pettersen <snowp@squareup.com>
jpsim
added a commit
that referenced
this pull request
Nov 28, 2022
Co-authored-by: jpsim <jpsim@users.noreply.github.com> Signed-off-by: GitHub Action <noreply@github.com> Signed-off-by: JP Simard <jp@jpsim.com>
jpsim
added a commit
that referenced
this pull request
Nov 29, 2022
Co-authored-by: jpsim <jpsim@users.noreply.github.com> Signed-off-by: GitHub Action <noreply@github.com> Signed-off-by: JP Simard <jp@jpsim.com>
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.
When envoy is launched with an empty yaml file through
-cit blows up with:This happens because the yaml loader correctly reads the file as a null value but converting this into a rapidjson object fails because the Null type isn't handled. This PR simply adds a switch case that handles this case by returning a null json object.
Risk Level: Low, it makes the json generator more permissive
Testing:
Added unit test that verifies that an empty string can be parsed as yaml and converted to a json string. Also verified that envoy doesn't crash when given an empty yaml file: