Skip to content
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

fix: IncomingRequest::getJsonVar() may cause TypeError #5392

Merged
merged 2 commits into from
Dec 1, 2021

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Nov 25, 2021

Description
Fixes #5391

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • [] User guide updated
  • Conforms to style guide

See codeigniter4#5391

[TypeError]
dot_array_search(): Argument #2 ($array) must be of type array, null given, called in .../system/HTTP/IncomingRequest.php on line 540
at SYSTEMPATH/Helpers/array_helper.php:21
@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 25, 2021
ErrorException: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated
@iRedds
Copy link
Collaborator

iRedds commented Nov 26, 2021

JSON can contain null as a value. Therefore, I do not know if this way of solving the problem is correct.

@kenjis
Copy link
Member Author

kenjis commented Nov 26, 2021

If the user input is 'null', json_decode() returns null.
null is not an array, so there is no value for a key $index.

@iRedds
Copy link
Collaborator

iRedds commented Nov 26, 2021

i mean

// body: {"var" : null}
$request->getVar('var'); // null

// body: {}
$request->getVar('var'); // null

// body: null
$request->getVar('var'); // null

If we assume that the value "var" can be null, then the last two examples are incorrect behavior.
And it seems to me you need to throw an exception.

If we compare it with working with an array, then:

$a = [];
$a['test'];
// Warning:  Undefined array key "test"

$a = null;
$a['test'];
// Warning:  Trying to access array offset on value of type null

@kenjis
Copy link
Member Author

kenjis commented Nov 26, 2021

It depends on getJsonVar()'s specification.
It throws an exception or not.

If it should throw an exception, #5391 is not a bug.

@kenjis kenjis merged commit d7ad228 into codeigniter4:develop Dec 1, 2021
@kenjis kenjis deleted the fix-getJsonVar branch December 1, 2021 03:49
@samsonasik
Copy link
Member

@kenjis could you verify PHPUnit error on develop branch?

@kenjis
Copy link
Member Author

kenjis commented Dec 2, 2021

@samsonasik Do you mean this?

PHP Fatal error: Declaration of PhpCoveralls\Bundle\CoverallsBundle\Console\Application::getDefinition() must be compatible with Symfony\Component\Console\Application::getDefinition(): Symfony\Component\Console\Input\InputDefinition in /home/runner/.composer/vendor/php-coveralls/php-coveralls/src/Bundle/CoverallsBundle/Console/Application.php on line 44
https://github.com/codeigniter4/CodeIgniter4/runs/4376649089?check_suite_focus=true

It is an error of PhpCoveralls: php-coveralls/php-coveralls#327

@samsonasik
Copy link
Member

Yes, is there a way to pin to specific coveralls version that is working?

@kenjis
Copy link
Member Author

kenjis commented Dec 2, 2021

Adding this to composer.json?

"symfony/console": "< 6.0",

@samsonasik
Copy link
Member

Yes, that's probably the temporary fix 👍

@kenjis
Copy link
Member Author

kenjis commented Dec 2, 2021

@samsonasik Okay, I will do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: public function getJsonVar error in the code
4 participants