Skip to content

Fix Intervals::isSubsetOf() with excluded branches listed more than once - #197

Open
bardrop wants to merge 1 commit into
composer:mainfrom
bardrop-oss:fix-subset-branch-name-keys
Open

bardrop wants to merge 1 commit into
composer:mainfrom
bardrop-oss:fix-subset-branch-name-keys

Conversation

@bardrop

@bardrop bardrop commented Nov 25, 2026

Copy link
Copy Markdown

Intervals::isSubsetOf() fails for some constraints that exclude branches, even against themselves:

$p = new VersionParser;
$c = $p->parseConstraints('!= dev-foo, != dev-bar || != dev-bar');
Intervals::isSubsetOf($c, $c); // Warning: Undefined array key 0, returns false

Intervals::isSubsetOf($p->parseConstraints('!= dev-foo, != dev-foo, != dev-bar'), $p->parseConstraints('!= dev-foo'));
// Warning: Undefined array key 1, returns false

generateIntervals() builds the branch names with array_unique(), array_intersect() and array_diff(), which keep the keys, so the list can have gaps (array(1 => 'dev-bar')). isSubsetOf() compares the names of the candidate and of the intersection by index, and the intersection of two excluding constraints is built with array_merge(), which starts at 0 again. Where a handler turns warnings into exceptions, this throws.

The names are now reindexed at the end of generateIntervals(), so they are always a list.

Tests: 3 cases in SubsetsTest and 2 in IntervalsTest, all fail before the change. The full suite (2308 tests) passes, and phpstan reports nothing in the touched files. I also compared isSubsetOf(), haveIntersections() and compactConstraint() with matches() over 20 versions and branches for 45,000 random constraint pairs: no difference is left, apart from constraints that match nothing.

The branch names kept the keys of array_unique()/array_intersect(), so
comparing them by index hit an undefined key and returned false.
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.

1 participant