fix(generator): correct PURL encoding for model IDs#18
fix(generator): correct PURL encoding for model IDs#18arunsanna wants to merge 1 commit intoGenAI-Security-Project:mainfrom
Conversation
Replace no-op `.replace('/', '/')` with `.replace('/', '%2F')` to
properly URL-encode forward slashes in model IDs per the PURL spec.
This fix ensures PURLs like `pkg:huggingface/meta-llama/Llama-3.1-8B`
are correctly encoded as `pkg:huggingface/meta-llama%2FLlama-3.1-8B`.
Fixes GenAI-Security-Project#13
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where .replace('/', '/') no-op calls prevented proper URL encoding of forward slashes in model IDs, resulting in invalid Package URLs (PURLs) that don't comply with the PURL specification.
Changes:
- Corrected 6 instances of
.replace('/', '/')to.replace('/', '%2F')to properly URL-encode forward slashes in model IDs - Ensures PURL identifiers like
pkg:huggingface/meta-llama/Llama-3.1-8B@1.0are correctly encoded aspkg:huggingface/meta-llama%2FLlama-3.1-8B@1.0 - Makes PURL generation consistent with existing correctly-encoded instances already in the codebase
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test Results ✅Tested with 3 different HuggingFace models to verify the fix: Test 1:
|
Fixes GenAI-Security-Project#15 - Add unit test infrastructure for the AIBOM Generator Added: - tests/ directory with pytest configuration - conftest.py with mock HuggingFace API fixtures - test_generator.py with 15 tests for AIBOMGenerator - test_scoring.py with 7 tests for completeness scoring - Sample fixtures for testing (sample_model_card.json, expected_aibom.json) - pytest.ini configuration - Test dependencies in requirements.txt (pytest, pytest-mock, pytest-cov) Test coverage: - AIBOM generation structure validation - CycloneDX compliance checks - PURL encoding (xfail until PR GenAI-Security-Project#18 merged) - Model card extraction - Error handling - Model ID normalization - Completeness scoring All tests run offline using mocked HuggingFace API responses. Results: 21 passed, 1 xfailed (expected)
- Remove unused variable `result` in test_generate_aibom_with_output_file - Simplify xfail reason to just reference PR GenAI-Security-Project#18 - Remove unused `import pytest` from test_scoring.py - Replace permissive `or` assertions with specific checks
✅ Testing Completed - VERIFIEDTest Space: https://megamind1-aibom-pr18-purl-fix.hf.space Test Results
Comparison
Ready for merge. ✓ |
Status Update: Superseded by v0.2This PURL encoding fix has been incorporated into the v0.2 branch architecture. Evidence: This PR can be closed as the fix is already in v0.2. See PR #36 for the consolidated v0.2 reapplication. |
Summary
.replace('/', '/')calls that were intended to URL-encode forward slashes in model IDs.replace('/', '%2F')to properly encode per the PURL specificationProblem
The code had 6 instances of
.replace('/', '/')which does nothing (replaces/with/). This resulted in invalid PURLs like:Solution
Changed to
.replace('/', '%2F')to produce valid PURLs:Test plan
meta-llama/Llama-3.1-8Bmodelbom-refandpurlfields contain%2FencodingFixes #13