Skip to content

Conversation

@mambax7
Copy link
Collaborator

@mambax7 mambax7 commented Jan 1, 2026

Solves the issue of XOOPS reporting that 2.5.12-beta is wrong version when the min. was set for 2.5.12

  • Anything below 2.5.12 → ❌ reject
  • Anything 2.5.12 (stable, beta, rc, alpha, etc.) → ✅ accept
  • Anything above 2.5.12 (2.5.13+, even alpha/beta) → ✅ accept

Copilot AI review requested due to automatic review settings January 1, 2026 16:27
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the versionCompare() method in the module class to correctly handle version strings with suffixes like -beta, -alpha, -rc, and -stable. The key improvement is that versions with the same base number are now treated as equal regardless of their suffix, which fixes the issue where 2.5.12-beta was incorrectly rejected when the minimum version was set to 2.5.12.

Key Changes:

  • Refactored version comparison to extract and compare only base version numbers (stripping suffixes)
  • Versions with identical base numbers are now treated as equal regardless of suffix
  • Simplifies the logic by normalizing both versions consistently before comparison

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 196 to 220
public function versionCompare($version1 = '', $version2 = '', $operator = '<')
{
$version1 = strtolower($version1);
$version2 = strtolower($version2);
if (false !== strpos($version2, '-stable')) {
$version2 = substr($version2, 0, strpos($version2, '-stable'));
}
if (false !== strpos($version1, '-stable')) {
$version1 = substr($version1, 0, strpos($version1, '-stable'));
$normalize = static function ($ver) {
$ver = strtolower($ver);
// strip suffix like -beta, -alpha, -rc, -stable
if (false !== ($pos = strpos($ver, '-'))) {
$ver = substr($ver, 0, $pos);
}
return $ver;
};

$base1 = $normalize($version1);
$base2 = $normalize($version2);

// Compare only the base versions first
$cmp = version_compare($base1, $base2);

if ($cmp === 0) {
// Same base version → treat as equal, regardless of suffix
return version_compare('0', '0', $operator);
}
return version_compare($version1, $version2, $operator);

// Otherwise, just use the base numeric comparison
return version_compare($base1, $base2, $operator);
}
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The updated version comparison logic lacks test coverage. Since this repository has existing PHPUnit test infrastructure (tests/unit/), and this is a critical function used for version validation across the system, unit tests should be added to verify the new behavior handles all edge cases correctly, including:

  • Same base version with different suffixes (e.g., 2.5.12 vs 2.5.12-beta)
  • Different base versions with suffixes (e.g., 2.5.11-stable vs 2.5.12-beta)
  • All comparison operators (<, <=, >, >=, ==, !=)
  • Edge cases like empty strings or malformed version strings

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Normalize legacy "-stable" (keep behavior consistent)
if (($pos = strpos($ver, '-stable')) !== false) {
$ver = substr($ver, 0, $pos);
$ver = rtrim($ver);
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The rtrim($ver) call on line 203 is redundant because line 211 already trims the entire string at the end of the normalization function. Additionally, the initial trim() on line 199 removes leading and trailing whitespace. This extra trim operation has no effect and can be removed.

Suggested change
$ver = rtrim($ver);

Copilot uses AI. Check for mistakes.
Comment on lines 200 to 206
// Normalize legacy "-stable" (keep behavior consistent)
if (($pos = strpos($ver, '-stable')) !== false) {
$ver = substr($ver, 0, $pos);
$ver = rtrim($ver);
}

// Strip any suffix after first '-': -beta, -alpha, -rc, -dev, etc.
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The special handling for -stable on lines 201-204 is redundant since lines 207-209 already strip any suffix starting with -, which would include -stable. The comment mentions "keep behavior consistent" but the behavior would be identical without this block. Consider removing lines 201-204 to simplify the logic and avoid confusion.

Suggested change
// Normalize legacy "-stable" (keep behavior consistent)
if (($pos = strpos($ver, '-stable')) !== false) {
$ver = substr($ver, 0, $pos);
$ver = rtrim($ver);
}
// Strip any suffix after first '-': -beta, -alpha, -rc, -dev, etc.
// Strip any suffix after first '-': -beta, -alpha, -rc, -dev, -stable, etc.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
return version_compare($version1, $version2, $operator);

return (bool)version_compare($n1, $n2, $op);
Copy link

Copilot AI Jan 1, 2026

Choose a reason for hiding this comment

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

The explicit cast to (bool) on line 215 is unnecessary. The version_compare() function already returns a boolean when an operator is provided, so the cast is redundant.

Suggested change
return (bool)version_compare($n1, $n2, $op);
return version_compare($n1, $n2, $op);

Copilot uses AI. Check for mistakes.
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