Skip to content

Accept CPE 2.3 locators with unescaped special characters#894

Open
arpitjain099 wants to merge 1 commit into
spdx:mainfrom
arpitjain099:chore/cpe23-validation-plus
Open

Accept CPE 2.3 locators with unescaped special characters#894
arpitjain099 wants to merge 1 commit into
spdx:mainfrom
arpitjain099:chore/cpe23-validation-plus

Conversation

@arpitjain099

Copy link
Copy Markdown

The cpe23Type validation regex (CPE23TYPE_REGEX in external_package_ref_validator.py) required a literal backslash immediately before the special-character class, in two places: (\\[\\\*\?!...]). That meant a special character like + had to be backslash-escaped to validate, so well-formed CPE 2.3 strings were rejected when a field contained an unescaped +. Examples from #796:

  • cpe:2.3:a:ahmed_h.:spdx-tools:0.8.3.dev1+g8050fd9c:*:*:*:*:*:*:* (+ in the version)
  • cpe:2.3:a:debian_gcc_maintainers:libstdc++6:12.2.0-9:*:*:*:*:*:*:* (+ in the product)

The fix drops that stray leading backslash so the special-character class is matched directly (([\\\*\?!...])). The class still contains \, so genuinely escaped sequences keep working; it just no longer requires the escape. Credit to @billie-alsup who pinpointed this in the issue thread.

I checked the regex against the reported strings plus the existing valid examples: the three failing cases now match and the previously-passing ones are unchanged. Added two test_valid_external_package_ref cases (+ in version and in product); pytest tests/spdx/validation/test_external_package_ref_validator.py passes (54).

This is scoped to the unescaped-special-character problem. The separate empty-field observation in the thread (e.g. 10.04::lts) is left out, since that touches the grammar more broadly and the spec example itself trips it.

Fixes #796

The cpe23Type validation regex required a literal backslash before the
special-character class in two places, so valid CPE 2.3 strings whose
version or product field contains a character such as "+" (for example
spdx-tools 0.8.3.dev1+g8050fd9c, or libstdc++6) were rejected even
though they are well formed per the CPE 2.3 grammar.

Drop the stray leading backslash so the special characters match
directly. Adds validation cases for "+" in the version and product
fields.

Fixes spdx#796

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.

Incorrect cpe23Type validation?

1 participant