Commit e84d176
fix: handle ~= and != version operators in Python dependency name parsing (guacsec#447)
## Summary
- Fix `getDependencyName()` to recognize `~` and `!` as PEP 508 version
operator characters, preventing them from being included in the package
name (e.g. `urllib3~=1.26.0` was parsed as package `urllib3~` instead of
`urllib3`)
- Replace the fragile three-index `getFirstSign()` approach with a
simple loop over all PEP 508 operator characters (`>`, `<`, `=`, `~`,
`!`)
- Add unit tests for compatibility (`~=`) and exclusion (`!=`)
operators, including combined extras + special operators
Implements [TC-4041](https://redhat.atlassian.net/browse/TC-4041)
## Test plan
- [x] All 358 existing unit tests pass
- [x] New unit tests verify `~=` and `!=` parsing
- [x] Manual CLI test with example `requirements.txt` from the ticket
produces correct SBOM
🤖 Generated with [Claude Code](https://claude.com/claude-code)
## Summary by Sourcery
Fix Python requirement parsing to correctly extract dependency names
when PEP 508 version operators are present, and extend tests to cover
these cases.
Bug Fixes:
- Correct dependency name extraction from Python requirement strings
that include PEP 508 operators such as ~=, !=, >=, <=, >, and < so
operator characters are not treated as part of the package name.
Enhancements:
- Simplify version operator detection in Python requirement parsing by
scanning for any PEP 508 operator character instead of relying on
multiple index lookups.
Tests:
- Add unit tests covering compatibility (~=) and exclusion (!=)
operators, including cases combining extras with special version
operators.
[TC-4041]:
https://redhat.atlassian.net/browse/TC-4041?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent b2119d6 commit e84d176
4 files changed
Lines changed: 70 additions & 18 deletions
File tree
- src
- main/java/io/github/guacsec/trustifyda
- providers
- utils
- test/java/io/github/guacsec/trustifyda
- providers
- utils
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
213 | 218 | | |
214 | 219 | | |
215 | 220 | | |
| |||
Lines changed: 11 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
395 | 400 | | |
396 | | - | |
| 401 | + | |
397 | 402 | | |
398 | 403 | | |
399 | | - | |
| 404 | + | |
400 | 405 | | |
401 | 406 | | |
402 | 407 | | |
403 | 408 | | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | 409 | | |
417 | 410 | | |
418 | 411 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
270 | 303 | | |
271 | 304 | | |
272 | 305 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
304 | 314 | | |
305 | 315 | | |
306 | 316 | | |
| |||
313 | 323 | | |
314 | 324 | | |
315 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
316 | 337 | | |
317 | 338 | | |
318 | 339 | | |
| |||
0 commit comments