daylerees / sanitizer

Sanitize data using a number of mutation methods.
259 stars 22 forks source link

No standardize data with Laravel #3

Closed edguerrade closed 10 years ago

edguerrade commented 10 years ago

Case: No standardize data with Laravel 4.1.* app/config/app.php as readme

UserController.php

$rules = [
    'first_name'  => 'trim|strtolower|ucwords',
    'last_name'   => 'trim|strtolower|ucwords',
    'email'       => 'trim|strtolower'
];
$data = Input::all();
Sanitizer::sanitize($rules, $data);
var_dump($data);

Input (example )

array(9) { ["_method"]=> string(3) "PUT" ["_token"]=> string(40) "wrJ1oSeexCCx7s5DPTdpwqBReBWlogun3BniIJJU" ["first_name"]=> string(26) "graceAAAAA " ["last_name"]=> string(7) "Johnson" ["email"]=> string(27) "grace.johnson56@EXAMPLE.com" ["tel"]=> string(0) "" ["dob"]=> string(10) "1970-03-23" ["description"]=> string(17) "password: scottie" ["image"]=> NULL }

Output (Look first_name or email value)

array(9) { ["_method"]=> string(3) "PUT" ["_token"]=> string(40) "wrJ1oSeexCCx7s5DPTdpwqBReBWlogun3BniIJJU" ["first_name"]=> string(26) "graceAAAAA " ["last_name"]=> string(7) "Johnson" ["email"]=> string(27) "grace.johnson56@EXAMPLE.com" ["tel"]=> string(0) "" ["dob"]=> string(10) "1970-03-23" ["description"]=> string(17) "password: scottie" ["image"]=> NULL }

Sorry about my english. Thanks!

edguerrade commented 10 years ago

If I use Stand-alone instead of Facade it works.

daylerees commented 10 years ago

Hmm, this is strange. I'll take a look when I find 5 minutes. Thanks mate.

JoeCianflone commented 10 years ago

I'm seeing this bug too. I'm using Laravel 4.2 on homestead. It seems to be something with the $data being passed-by-reference. If I remove the & from the $data parameter in the sanitizer() method in Sanitize.phpand add a return $data to the end of that method I'll get my correctly sanitized data, but whatever I'm doing, that seems to be the only way to get the correct data back. @daylerees I have a fully working example of this bug but it's more than one file to send. I can give you access to my repo and point you to the files if you need to see it in action

jotafurtado commented 10 years ago

Same issue here. I'm using Laravel 4.2.