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

Make caseless remove robust #440

Merged
merged 1 commit into from
Oct 4, 2021
Merged

Conversation

GrahamCampbell
Copy link
Member

@GrahamCampbell GrahamCampbell commented Sep 6, 2021

Related to #429. Allows for validation to happen downstream instead of crashing on an internal error. Also, the type information on this function technically says any kind of array key is allowed, sooo. ;)

As to why fix this only on 2.x? On 1.x, it was actually doing casting for us, so the behaviour there was to remove keys with integer value 1 if the string key was '1'. This PR instead skips over integer keys, which I think is the better behaviour, but also technically a breaking change. Since this is not working at all in 2.0.0, we're good to make that change in 2.1.0. :trollface:

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Im happy with this PR but I want to get some more info.

This PR instead skips over integer keys, which I think is the better behaviour, but also technically a breaking change.

How is this a BC break? If a user has an integer key, it will be an error.
With this PR, we will never remove integer keys.

I don't see any application breaking because of this.

@@ -25,7 +25,7 @@ public static function caselessRemove(array $keys, array $data): array
}

foreach ($data as $k => $v) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we also want to add @param array<string, mixed> $data on this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. That would be a breaking change. I'd be happy to do this in a possible future 3.x version, though.

@GrahamCampbell
Copy link
Member Author

How is this a BC break? If a user has an integer key, it will be an error.

Not according to the function documentation. It says any array can be passed. Indeed people are doing this: #429. Guzzle does have a mechanism for letting them know when they made an error like this, but that exception gets hidden because the code crashes early, here.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Hm.
I still dont see how this could break BC.

Im happy to move forward with this.

@GrahamCampbell GrahamCampbell merged commit c7b89ff into master Oct 4, 2021
@GrahamCampbell GrahamCampbell deleted the robust-caseless-remove branch October 4, 2021 20:41
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

Successfully merging this pull request may close these issues.

None yet

2 participants