Skip to content

Treat single Tomcat pre-release versions as exact versions - #2531

Open
nikolya-ctrl wants to merge 2 commits into
aboutcode-org:mainfrom
nikolya-ctrl:fix-2528-tomcat-prerelease
Open

nikolya-ctrl wants to merge 2 commits into
aboutcode-org:mainfrom
nikolya-ctrl:fix-2528-tomcat-prerelease

Conversation

@nikolya-ctrl

@nikolya-ctrl nikolya-ctrl commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #2528

Problem

In apache_tomcat_importer.py, both to_version_ranges_apache and to_version_ranges_maven treated any version containing - as an A-B range. Single pre-release versions like 11.0.0-M5 or 8.0.0-RC1 were split into >=11.0.0 and <=M5, so the affected pre-release was marked as not affected and later stable releases were marked as affected.

Fix

Only treat - as a range when the part after the dash starts with a digit (e.g. 7.0.0-7.0.53). Otherwise the value falls through to the existing single-version branch.

Tests

Added tests for:

  • a real range (7.0.0-7.0.53) to make sure existing behaviour is unchanged
  • single pre-releases 11.0.0-M5 and 8.0.0-RC1 (Apache)
  • single pre-release 11.0.0-M5 (Maven)

All 8 tests in test_apache_tomcat_importer_pipeline.py pass locally (Python 3.13, WSL Ubuntu).

Before / after (reproduction script from the issue)

Before:

pkg:apache/tomcat -> vers:apache/!=11.0.0|>=11.0.0
  11.0.0-M5 in range: False
  11.0.2    in range: True

After:

pkg:apache/tomcat -> vers:apache/11.0.0-M5|!=11.0.0
  11.0.0-M5 in range: True
  11.0.2    in range: False

Note

The !=11.0.0 in the output comes from how the fixed version (11.0.0-M6) is handled, which looks like a separate issue, so I left it out of this PR. Happy to look into it separately if that's useful.


I reproduced the bug, worked out the fix, implemented it with tests, and verified everything locally. I used an AI assistant as a learning aid while getting familiar with the codebase and to help word this description.

Versions like 11.0.0-M5 or 8.0.0-RC1 were split on '-' as A-B ranges. Only treat '-' as a range when the right side starts with a digit, in both to_version_ranges_apache and to_version_ranges_maven. Add tests. Fixes aboutcode-org#2528

Signed-off-by: Nikolya Fernando <238961989+nikolya-ctrl@users.noreply.github.com>

@Jean-Regis-M Jean-Regis-M left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested on this branch (Windows, pytest, no DB): test_apache_tomcat_importer_pipeline.py 8 passed.

Behaviour on current main for a single milestone version vs this PR:

  • 11.0.0-M5: main gives vers:apache/>=11.0.0 (and vers:maven/<=M5|>=11.0.0), so everything from 11.0.0 up reads as affected. This PR gives vers:apache/11.0.0-M5.
  • <10.1.0-M3: main gives vers:maven/<=M3|>=<10.1.0. This PR takes the < branch and gives <10.1.0-M3.
  • Real ranges (8.5.0-8.5.50, 11.0.0-M1 to 11.0.0-M5) come out the same as before.

One edge: version_item.split("-")[-1][0] raises IndexError on a trailing hyphen (7.0.0-). On main that case produces a junk range, here the exception reaches the except in the importer loop and the whole CVE entry is skipped. Unlikely on the real page, but [-1][:1].isdigit() avoids it.

With #2534 applied on top, the milestone fixed version and the single-version affected range line up (vers:apache/11.0.0-M5|!=11.0.0-M6). The two PRs only conflict in the test file, since both append at the end.

Use [:1] instead of [0] when checking the part after '-', so a value like '7.0.0-' no longer raises IndexError. Add a test. Suggested in review of aboutcode-org#2531.

Signed-off-by: Nikolya Fernando <238961989+nikolya-ctrl@users.noreply.github.com>
@nikolya-ctrl

Copy link
Copy Markdown
Author

Thanks for testing this so thoroughly, @Jean-Regis-M!

Good catch on the trailing hyphen. I switched both checks to [-1][:1].isdigit() and added test_to_version_ranges_apache_trailing_hyphen_does_not_crash, so 7.0.0- no longer raises IndexError. All 9 tests in test_apache_tomcat_importer_pipeline.py pass.

Also thanks for checking it together with #2534. I'll rebase whichever one is merged second to resolve the test file conflict.

This branch has not been deployed

No deployments
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.

ApacheTomcatImporterPipeline splits single hyphenated pre-release versions (e.g. 11.0.0-M5) on '-' as version ranges

2 participants