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

Bug: Validation on null for trim #7067

Closed
ValdisM opened this issue Jan 9, 2023 · 6 comments
Closed

Bug: Validation on null for trim #7067

ValdisM opened this issue Jan 9, 2023 · 6 comments
Labels
waiting for info Issues or pull requests that need further clarification from the author

Comments

@ValdisM
Copy link

ValdisM commented Jan 9, 2023

PHP Version

8.1

CodeIgniter4 Version

4.2.5

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

macOS

Which server did you use?

apache

Database

No response

What happened?

trim() on null is not working for validation.

I suggest to edit: Validation.php Line 302:

$passed = $param === false ? $rule((string) $value ?? '') : $rule((string) $value ?? '', $param, $data);

Steps to Reproduce

make rule without a post.

Expected Output

Expected:\

Previous:
$passed = $param === false ? $rule($value) : $rule($value, $param, $data);

$passed = $param === false ? $rule((string) $value ?? '') : $rule((string) $value ?? '', $param, $data);

Anything else?

No response

@ValdisM ValdisM added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 9, 2023
@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 10, 2023
@kenjis
Copy link
Member

kenjis commented Jan 10, 2023

Sorry, I don't get what you say. Why do you use trim()?
Validation never alters input data.

Can you show exact Steps to Reproduce?

@kenjis kenjis added the waiting for info Issues or pull requests that need further clarification from the author label Jan 11, 2023
@kenjis
Copy link
Member

kenjis commented Feb 27, 2023

If you still think this is a bug, feel free to reopen.

@kenjis kenjis closed this as completed Feb 27, 2023
@pietos
Copy link

pietos commented Jul 14, 2023

I have the same issue, when you post an empty value on a form validation where you specified trim it results into:

"message": "trim(): Passing null to parameter #1 ($string) of type string is deprecated",
"file": "C:\docker_xampp\htdocs\slurpee_portal\system\Validation\Validation.php",

@kenjis
Copy link
Member

kenjis commented Jul 14, 2023

If you specify trim in the validation rules, the Validation does not trim the value.
Why do you need to specify trim ?

@pietos
Copy link

pietos commented Jul 15, 2023

Well, the problem is not trim but the function:
permit_empty

in the permit empty they do a trim on the value to see if it's really "", but when the value is NULL this results into this error.

system\Validation\Validation.php

image

@kenjis
Copy link
Member

kenjis commented Jul 16, 2023

Cannot reproduce.
If you can reproduce the error, please create an issue with minimum code to reproduce.

php > echo trim(null);
PHP Deprecated:  trim(): Passing null to parameter #1 ($string) of type string is deprecated in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
PHP   2. trim($string = NULL) php shell code:1
php > echo trim((string) null);
php > 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for info Issues or pull requests that need further clarification from the author
Projects
None yet
Development

No branches or pull requests

3 participants