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

[REF][PHP8.1] Batch 4 of fixing issues found in unit tests where pass… #24018

Merged
merged 1 commit into from
Jul 21, 2022

Conversation

seamuslee001
Copy link
Contributor

…ing NULL values triggers deprecations

Overview

This is the 4th batch of fixes for when we are passing NULL values to functions that don't like having NULL values passed to them in php8.1

Before

Deprecations triggered

After

Less Deprecations triggered

ping @eileenmcnaughton @totten @demeritcowboy @colemanw

@civibot
Copy link

civibot bot commented Jul 19, 2022

(Standard links)

@@ -67,7 +67,7 @@ public static function add(&$params, $ids = []) {
if (empty($params['name']) && empty($params['id'])) {
$params['name'] = CRM_Utils_String::titleToVar(strtolower($params['title']));
}
elseif (!empty($params['name']) && strpos($params['name'], ' ')) {
elseif (!empty($params['name']) && strpos(($params['name'] ?? ''), ' ')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's odd. If $params['name'] is null it wouldn't even reach that clause. Is it actually null here or is it something like $params['name'] is an object, or a nested array?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find which test would be doing this. If it's not empty it can't be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok have updated I think your right but not 100% sure now

@@ -774,7 +774,7 @@ public static function parseStreetAddress($streetAddress, $locale = NULL) {
// the DB to fatal
$fields = CRM_Core_BAO_Address::fields();
foreach ($fields as $fieldname => $field) {
if (!empty($field['maxlength']) && strlen(CRM_Utils_Array::value($fieldname, $parseFields)) > $field['maxlength']) {
if (!empty($field['maxlength']) && strlen(CRM_Utils_Array::value($fieldname, $parseFields, '')) > $field['maxlength']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to get rid of this function. Can it just be $parseFields[$fieldname] ?? ''. We know $parseFields is an array so don't have to think about that goofiness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a couple others lower down - will attack them later.

@@ -1138,7 +1138,7 @@ public static function isDir(?string $dir) {
return FALSE;
});
try {
$is_dir = is_dir($dir);
$is_dir = is_dir($dir ?? '');
Copy link
Contributor

@demeritcowboy demeritcowboy Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one I'd like to check what they did upstream in php itself with their unit tests. For security reasons this function should behave identical to is_dir with some small exceptions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it looks like php itself does not have a test for null on this. My worry is that there is some edge-case situation where the empty string would return true even though you passed in null, bypassing security. I'm thinking the answer is to update the test to expect something different based on php version, since that is what is actually the case.

I'll take a stab at that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky because it's a deprecation which is hard to get at. How about for now just before the try on line 1140:

if ($dir === NULL) {
  return FALSE;
}

instead of the ?? ''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or no wait it would have to be before the set_error_handler - the very first thing in the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@seamuslee001 seamuslee001 force-pushed the php8_1_null_batch_4 branch 2 times, most recently from deb4b42 to 5278e0e Compare July 20, 2022 21:36
…ing NULL values triggers deprecations

Apply fixes as per Demeritcowboy
@demeritcowboy demeritcowboy merged commit ef02c66 into civicrm:master Jul 21, 2022
@eileenmcnaughton eileenmcnaughton deleted the php8_1_null_batch_4 branch July 21, 2022 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants