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

Don't mutate $limit argument from 0 to -1 and from -1 to 0 in preg_split function #1347

Merged
merged 3 commits into from Oct 21, 2020

Conversation

sidz
Copy link
Member

@sidz sidz commented Oct 18, 2020

This PR stops mutate $limit argument from 0 to -1 and from -1 to 0 in preg_split function.

Requested in #1345

@maks-rafalko maks-rafalko added this to the 0.19 milestone Oct 18, 2020
@vjik
Copy link

vjik commented Oct 18, 2020

It is wrong to completely deny mutations.
There must be mutations more 0 and less -1.

@sidz
Copy link
Member Author

sidz commented Oct 18, 2020

@vjik added more tests to show that it works.

But found an issue with Decrement mutator when
preg_split('//', 'string', 1);

Because of:

if (!$node instanceof Node\Scalar\LNumber || $node->value === 1) {
return false;
}

and similar with Increment mutator when:
preg_split('//', 'string', 0);

Because of:

return $node instanceof Node\Scalar\LNumber
&& $node->value !== 0
&& !$this->isPartOfSizeComparison($node);

@vjik
Copy link

vjik commented Oct 18, 2020

See #1350

IncrementInteger work fine without fixes. Problems with DecrementInteger and OneZeroInteger.

@sidz
Copy link
Member Author

sidz commented Oct 19, 2020

@vjik IncrementInteger doesn't work - https://infection-php.dev/r/1lr (proof)

@vjik
Copy link

vjik commented Oct 19, 2020

@vjik IncrementInteger doesn't work - https://infection-php.dev/r/1lr (proof)

IncrementInteger don't work for preg_split('//', 'string', -1); => preg_split('//', 'string', 0); — that is right.
In other cases IncrementInteger it works — thas is also right.

@sidz sidz changed the title Don't mutate $limit argument from 0 to -1 and from -1 to 0 in preg_split function [WIP] Don't mutate $limit argument from 0 to -1 and from -1 to 0 in preg_split function Oct 19, 2020
@sidz sidz force-pushed the do-not-mutate-zero-minus-one-in-preg-split branch from 075476b to fe4adfd Compare October 20, 2020 19:50
@sidz sidz changed the title [WIP] Don't mutate $limit argument from 0 to -1 and from -1 to 0 in preg_split function Don't mutate $limit argument from 0 to -1 and from -1 to 0 in preg_split function Oct 20, 2020
Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

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

👌

@sidz
Copy link
Member Author

sidz commented Oct 20, 2020

@vjik I suppose all possible cases were covered. PR is ready for review.

IncrementInteger don't work for preg_split('//', 'string', -1); => preg_split('//', 'string', 0); — that is right.

It didn't work right as mutators had an issue with negative values. This behavior was fixed in #1351. So current master will mutate values from -1 to 0.

@sidz sidz removed the In Progress label Oct 20, 2020
@sidz sidz requested a review from sanmai October 20, 2020 20:07
Copy link
Member

@sanmai sanmai left a comment

Choose a reason for hiding this comment

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

Tests are sensible.

@maks-rafalko maks-rafalko merged commit 1d82648 into master Oct 21, 2020
@maks-rafalko maks-rafalko deleted the do-not-mutate-zero-minus-one-in-preg-split branch October 21, 2020 09:50
@maks-rafalko
Copy link
Member

Thank you @sidz 👍

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

4 participants