Skip to content

[ENG-2586] Harden version comparison with stricter normalization and expanded tests#1

Merged
devlob merged 8 commits into
mainfrom
feature/ENG-2586-version-compare-hardening
Apr 15, 2026
Merged

[ENG-2586] Harden version comparison with stricter normalization and expanded tests#1
devlob merged 8 commits into
mainfrom
feature/ENG-2586-version-compare-hardening

Conversation

@devlob
Copy link
Copy Markdown
Contributor

@devlob devlob commented Apr 15, 2026

  • Extract normalizeVersion() to safely strip v-prefix without corrupting versions containing 'v' in body (e.g., 6.3-revision-0, 5.0.37.preview)
  • Use strict === comparisons and explicit empty checks instead of loose ==
  • Fix range detection regex to avoid misinterpreting dashed versions as ranges
  • Replace strpos/stripos with str_contains/str_starts_with (PHP 8.1+)
  • Add edge case tests: scientific notation coercion, whitespace-only input, malformed operators, compound dashes, decimal strategy coverage

…expanded tests

- Extract normalizeVersion() to safely strip v-prefix without corrupting
  versions containing 'v' in body (e.g., 6.3-revision-0, 5.0.37.preview)
- Use strict === comparisons and explicit empty checks instead of loose ==
- Fix range detection regex to avoid misinterpreting dashed versions as ranges
- Replace strpos/stripos with str_contains/str_starts_with (PHP 8.1+)
- Add edge case tests: scientific notation coercion, whitespace-only input,
  malformed operators, compound dashes, decimal strategy coverage
@devlob
Copy link
Copy Markdown
Contributor Author

devlob commented Apr 15, 2026

/review

devlob added 6 commits April 15, 2026 15:40
Pest v3 requires PHP 8.2+. The default template had PHP 8.1 in the
matrix which caused composer install to fail. Also adds Composer
dependency caching and PHP 8.4 to the matrix.
Pest v3 requires a phpunit.xml config in CI environments. Without it,
the --cache-directory flag is misinterpreted as an XML config path.
composer.lock is gitignored so CI resolves fresh — PHP 8.1 gets
Pest v2, PHP 8.2+ gets Pest v3. Tests the full declared range.
Pest v2.36.1+ and v3 both require PHP 8.2. PHP 8.1 reached EOL
Nov 2024. Update composer.json and CI matrix accordingly.
Package will be used in Hub (Laravel 12, PHP 8.4). No need to
support older versions.
Comment thread .github/workflows/tests.yml Outdated
Comment thread composer.json Outdated
$affectedIn = trim($affectedIn);
$currentVersion = trim($currentVersion);

if (empty($affectedIn) || empty($currentVersion)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't have a lot of background here, but what happens if the currentVersion or affectedIn come through as null? Right now, it looks like they get treated as empty strings, and we return false, which basically means “not vulnerable”.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because of declare(strict_types=1); that won't happen.

@devlob devlob force-pushed the feature/ENG-2586-version-compare-hardening branch from ae10a99 to 4b5296f Compare April 15, 2026 14:34
Hub and saas run PHP 8.2, so this package must support it.
No 8.4-specific features are used in the source code.
@devlob devlob force-pushed the feature/ENG-2586-version-compare-hardening branch from 4b5296f to 1912876 Compare April 15, 2026 14:35
@devlob devlob merged commit 5721c23 into main Apr 15, 2026
3 checks passed
@devlob devlob deleted the feature/ENG-2586-version-compare-hardening branch April 15, 2026 14:37
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.

3 participants