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

Ensure "dev-" prefix and "-dev" suffix is used correctly #1055

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/Vendor/Composer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$versionConstraint = self::removeExtraSpaces($versionConstraint);

try {
$this->versionParser->parseConstraints($versionConstraint);

Check warning on line 66 in src/Vendor/Composer/VersionConstraintNormalizer.php

View workflow job for this annotation

GitHub Actions / Mutation Tests (7.4, locked)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $versionConstraint = self::trim($versionConstraint); $versionConstraint = self::removeExtraSpaces($versionConstraint); try { - $this->versionParser->parseConstraints($versionConstraint); + } catch (\UnexpectedValueException $exception) { return $versionConstraint; }
} catch (\UnexpectedValueException $exception) {
return $versionConstraint;
}
Expand All @@ -85,6 +85,7 @@
{
$versionConstraint = self::normalizeVersionConstraintSeparators($versionConstraint);
$versionConstraint = self::removeLeadingVersionPrefix($versionConstraint);
$versionConstraint = self::assertDevPrefixSuffixPosition($versionConstraint);
$versionConstraint = self::replaceWildcardXWithAsterisk($versionConstraint);
$versionConstraint = self::replaceWildcardWithTilde($versionConstraint);
$versionConstraint = self::replaceTildeWithCaret($versionConstraint);
Expand Down Expand Up @@ -177,11 +178,45 @@
{
return self::applyRegularExpressionReplacementToVersionsInTurn(
$versionConstraint,
'{^(|[!<>]=|[~<>^])v(\d+.*)$}',
'{^(|[!<>]=|[~<>^])v(\d+.*(?<!-dev))$}',
'$1$2',
);
}

private static function assertDevPrefixSuffixPosition(string $versionConstraint): string
{
$split = \explode(
' ',
$versionConstraint,
);

foreach ($split as &$part) {
if (\strlen($part) <= 4) {
continue;
}

if (\strpos($part, 'dev-') === 0) {
$branch = \substr($part, 4);
} elseif (\substr($part, -4) === '-dev') {
$branch = \substr($part, 0, -4);
} else {
continue;
}

// @see https://github.com/composer/semver/blob/3.4.0/src/VersionParser.php#L216
if (\preg_match('{^v?\d+(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?$}i', $branch)) {
$part = $branch . '-dev';
} else {
$part = 'dev-' . $branch;
}
}

return \implode(
' ',
$split,
);
}

private static function removeOverlappingVersionConstraints(string $versionConstraint): string
{
$orConstraints = self::splitIntoOrConstraints($versionConstraint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
"branch/03-main-referencing-commit-trimmed": "dev-main#bf2eeff",
"branch/04-main-referencing-commit-untrimmed": "dev-main#bf2eeff",
"branch/05-my-feature-trimmed": "dev-my-feature",
"branch/06-my-feature-untrimmed": "dev-my-feature"
"branch/06-my-feature-untrimmed": "dev-my-feature",
"branch/07-main-suffix": "dev-main",
"branch/08-numeric-branch-lower-suffix-major": "1.x-dev",
"branch/09-numeric-branch-lower-suffix-major-minor": "1.2.x-dev",
"branch/10-numeric-branch-lower-prefix-major": "1.x-dev",
"branch/11-numeric-branch-lower-prefix-major-minor": "1.2.x-dev",
"branch/12-numeric-branch-upper-suffix-major": "1.X-dev",
"branch/13-numeric-branch-upper-suffix-major-minor": "1.2.X-dev",
"branch/14-numeric-branch-upper-prefix-major": "1.X-dev",
"branch/15-numeric-branch-upper-prefix-major-minor": "1.2.X-dev",
"branch/16-numeric-branch-starts-with-v-lower-suffix-major": "v1.x-dev",
"branch/17-numeric-branch-starts-with-v-lower-suffix-major-minor": "v1.2.x-dev",
"branch/18-numeric-branch-starts-with-v-lower-prefix-major": "v1.x-dev",
"branch/19-numeric-branch-starts-with-v-lower-prefix-major-minor": "v1.2.x-dev",
"branch/20-numeric-branch-starts-with-v-upper-suffix-major": "v1.X-dev",
"branch/21-numeric-branch-starts-with-v-upper-suffix-major-minor": "v1.2.X-dev",
"branch/22-numeric-branch-starts-with-v-upper-prefix-major": "v1.X-dev",
"branch/23-numeric-branch-starts-with-v-upper-prefix-major-minor": "v1.2.X-dev"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
"branch/03-main-referencing-commit-trimmed": "dev-main#bf2eeff",
"branch/04-main-referencing-commit-untrimmed": " dev-main#bf2eeff ",
"branch/05-my-feature-trimmed": "dev-my-feature",
"branch/06-my-feature-untrimmed": " dev-my-feature "
"branch/06-my-feature-untrimmed": " dev-my-feature ",
"branch/07-main-suffix": "main-dev",
"branch/08-numeric-branch-lower-suffix-major": "1.x-dev",
"branch/09-numeric-branch-lower-suffix-major-minor": "1.2.x-dev",
"branch/10-numeric-branch-lower-prefix-major": "dev-1.x",
"branch/11-numeric-branch-lower-prefix-major-minor": "dev-1.2.x",
"branch/12-numeric-branch-upper-suffix-major": "1.X-dev",
"branch/13-numeric-branch-upper-suffix-major-minor": "1.2.X-dev",
"branch/14-numeric-branch-upper-prefix-major": "dev-1.X",
"branch/15-numeric-branch-upper-prefix-major-minor": "dev-1.2.X",
"branch/16-numeric-branch-starts-with-v-lower-suffix-major": "v1.x-dev",
"branch/17-numeric-branch-starts-with-v-lower-suffix-major-minor": "v1.2.x-dev",
"branch/18-numeric-branch-starts-with-v-lower-prefix-major": "dev-v1.x",
"branch/19-numeric-branch-starts-with-v-lower-prefix-major-minor": "dev-v1.2.x",
"branch/20-numeric-branch-starts-with-v-upper-suffix-major": "v1.X-dev",
"branch/21-numeric-branch-starts-with-v-upper-suffix-major-minor": "v1.2.X-dev",
"branch/22-numeric-branch-starts-with-v-upper-prefix-major": "dev-v1.X",
"branch/23-numeric-branch-starts-with-v-upper-prefix-major-minor": "dev-v1.2.X"
}
}
Loading