8000 Symfony\Component\VarDumper\Caster\SymfonyCaster doesn't check array key exist · Issue #33751 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Symfony\Component\VarDumper\Caster\SymfonyCaster doesn't check array key exist #33751

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

Closed
zcodes opened this issue Sep 29, 2019 · 5 comments
Closed

Comments

@zcodes
Copy link
zcodes commented Sep 29, 2019

in the class method castRequest and castHttpClient, argument array $a is used without checking the array key exists, by default, there's no problem, but if there's filter before called SymfonyCaster (like in laravel's tinker), the array $a is empty, then it will raise an index error exception.

>>> use Symfony\Component\HttpClient\HttpClient;
>>> $c = HttpClient::create()
=> Symfony\Component\HttpClient\CurlHttpClient {#2993
     ⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {#3000
       #message: "Unexpected ErrorException thrown from a caster: Undefined index: ",
     },
   }
>>> use Symfony\Component\HttpFoundation\Request;
>>> $r = new Request()
=> Symfony\Component\HttpFoundation\Request {#3006
     ⚠: Symfony\Component\VarDumper\Exception\ThrowingCasterException {#3024
       #message: "Unexpected ErrorException thrown from a caster: Undefined index: ",
     },
     +attributes: Symfony\Component\HttpFoundation\ParameterBag {#3005},
     +request: Symfony\Component\HttpFoundation\ParameterBag {#3008},
     +query: Symfony\Component\HttpFoundation\ParameterBag {#3001},
     +server: Symfony\Component\HttpFoundation\ServerBag {#2998},
     +files: Symfony\Component\HttpFoundation\FileBag {#3007},
     +cookies: Symfony\Component\HttpFoundation\ParameterBag {#3003},
     +headers: Symfony\Component\HttpFoundation\HeaderBag {#3004},
   }
@zcodes zcodes changed the title Symfony\Component\VarDumper\Caster\SymfonyCaster doesn't check array key exits Symfony\Component\VarDumper\Caster\SymfonyCaster doesn't check array key exist Sep 29, 2019
@nicolas-grekas
Copy link
Member
nicolas-grekas commented Sep 30, 2019
< 8000 tbody class="d-block">

Hi, thanks for the report. Can you please share a reproducer? I just had a quick look at the source code of tinker and I don't get how it's related to request/http-client casters.
Please send a fix if you can also, with a test case of course.

@xabbuh
Copy link
Member
xabbuh commented Oct 7, 2019

@zcodes Do you have any news for us?

@zcodes
Copy link
Author
zcodes commented Oct 8, 2019

this is a piece of code demo the problem:

<?php

use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\VarDumper\Caster\Caster;

require_once __DIR__ . '/vendor/autoload.php';

$cloner = new VarCloner();
$cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
    if ($filter || $isNested) {
        if ($obj instanceof \Exception) {
            $a = Caster::filter($a, Caster::EXCLUDE_NOT_IMPORTANT | Caster::EXCLUDE_EMPTY);
        } else {
            $a = Caster::filter($a, Caster::EXCLUDE_PROTECTED | Caster::EXCLUDE_PRIVATE);
        }
    }

    return $a;
}]);

$client = HttpClient::create();
$data = $cloner->cloneVar($client, Caster::EXCLUDE_VERBOSE);

@nicolas-grekas
Copy link
Member

OK, got it thanks for the code. Many casters are affected then, isn't it?
Would you be able to work on a PR?

zcodes pushed a commit to zcodes/symfony that referenced this issue Oct 9, 2019
zcodes pushed a commit to zcodes/symfony that referenced this issue Oct 9, 2019
@zcodes
Copy link
Author
zcodes commented Oct 9, 2019

@nicolas-grekas I make a pr #33919 , hope this is helpful.

nicolas-grekas added a commit that referenced this issue Oct 9, 2019
…codes)

This PR was squashed before being merged into the 4.3 branch (closes #33919).

Discussion
----------

[VarDumper] fix array key error for class SymfonyCaster

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33751
| License       | MIT
| Doc PR        | -

Commits
-------

1f20f35 [VarDumper] fix array key error for class SymfonyCaster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0