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

Setting config filter_fields_parameter to null doesn't disable query string fieldset filtering #138

Open
mihai-scurtu opened this issue May 21, 2019 · 2 comments

Comments

@mihai-scurtu
Copy link

mihai-scurtu commented May 21, 2019

Responder version: 3.0.5
Laravel version: v5.5.45

In the config file, the documentation for filter_fields_parameter says:

The package can automatically filter the fields of transformed data from a query string parameter configured below. The technique is also known as sparse fieldsets. Set it to null to disable it.

However, when setting it to null I started getting Array to string conversion errors when I sent any query parameters.

I think the cause is here:

$this->app->bind(TransformBuilder::class, function ($app) {
            $request = $this->app->make(Request::class);
            $relations = $request->input($this->app->config['responder.load_relations_parameter'], []);
            $fieldsets = $request->input($app->config['responder.filter_fields_parameter'], []);

            return (new TransformBuilder($app->make(ResourceFactoryContract::class), $app->make(TransformFactoryContract::class), $app->make(PaginatorFactoryContract::class)))->serializer($app->make(SerializerAbstract::class))
                ->with(is_string($relations) ? explode(',', $relations) : $relations)
                ->only($fieldsets);
        });

I've set a xdebug breakpoint after the fieldsets and relations are parsed, and apparently sending null as the key returns the whole request input, as opposed to what I assume was the intended effect of an empty array.

Here is a screenshot of the debugger. What you see in the $fieldsets array is essentially the whole parsed query string:

image

@mihai-scurtu
Copy link
Author

I can fix this in my project by overriding that method in the service provider, but it still seems like a bug.

@flugg
Copy link
Owner

flugg commented Jun 6, 2019

Hey! This does indeed seem like an error. I'll look into it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants