7 files changed +38
-7
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## [ 5.2.2]
4
+
5
+ ### Bugfix
6
+
7
+ - Encode purls correctly in SBOM
8
+
3
9
## [ 5.2.1]
4
10
5
11
### Bugfix
Original file line number Diff line number Diff line change 4
4
*/
5
5
6
6
var exports = exports || { } ;
7
- exports . version = '5.2.1 ' ;
7
+ exports . version = '5.2.2 ' ;
8
8
9
9
function isDefined ( o ) {
10
10
return typeof o !== 'undefined' ;
Original file line number Diff line number Diff line change 2
2
"author" : " Erlend Oftedal <erlend@oftedal.no>" ,
3
3
"name" : " retire" ,
4
4
"description" : " Retire is a tool for detecting use of vulnerable libraries" ,
5
- "version" : " 5.2.1 " ,
5
+ "version" : " 5.2.2 " ,
6
6
"license" : " Apache-2.0" ,
7
7
"repository" : {
8
8
"type" : " git" ,
Original file line number Diff line number Diff line change
1
+ import { should } from 'chai' ;
2
+ import 'mocha' ;
3
+ should ( ) ;
4
+ import { generatePURL } from '../../lib/reporters/utils' ;
5
+
6
+ describe ( 'purl encoding' , ( ) => {
7
+ it ( 'should not touch a simple string' , ( ) => {
8
+ generatePURL ( { component : 'jquery' , version : '1.2.3' } ) . should . equal ( 'pkg:npm/jquery@1.2.3' ) ;
9
+ } ) ;
10
+ it ( 'should encode @ in package scopes' , ( ) => {
11
+ generatePURL ( { component : '@angular/core' , version : '1.2.3' } ) . should . equal ( 'pkg:npm/%40angular/core@1.2.3' ) ;
12
+ } ) ;
13
+ it ( 'should not doulbe encode' , ( ) => {
14
+ generatePURL ( { component : '%40angular/core' , version : '1.2.3' } ) . should . equal ( 'pkg:npm/%40angular/core@1.2.3' ) ;
15
+ } ) ;
16
+ } ) ;
Original file line number Diff line number Diff line change @@ -104,7 +104,7 @@ export function validateRepository(
104
104
bowername : z . array ( z . string ( ) . regex ( / ^ [ a - z 0 - 9 . - ] + $ / i) ) . optional ( ) ,
105
105
basePurl : z
106
106
. string ( )
107
- . regex ( / ^ p k g : [ a - z 0 - 9 / ] + $ / i)
107
+ . regex ( / ^ p k g : [ a - z 0 - 9 % . - / ] + $ / i)
108
108
. optional ( ) ,
109
109
npmname : z
110
110
. string ( )
Original file line number Diff line number Diff line change 1
1
import { Component } from '../types' ;
2
2
3
+ function encodePURLchars ( str : string ) : string {
4
+ return str . replace (
5
+ / [ ^ A - Z a - z 0 - 9 . + / = - % ] / g,
6
+ ( match ) => '%' + ( '0' + match . charCodeAt ( 0 ) . toString ( 16 ) . toUpperCase ( ) ) . slice ( - 2 ) ,
7
+ ) ;
8
+ }
9
+
3
10
export function generatePURL ( component : Component ) : string {
4
11
if ( component . basePurl ) {
5
- return component . basePurl + '@' + component . version ;
12
+ const [ pType , ...rest ] = component . basePurl . split ( ':' ) ;
13
+ const pathElements = rest . join ( ':' ) . split ( '/' ) . map ( encodePURLchars ) . join ( '/' ) ;
14
+ return `${ pType } :${ pathElements } @${ encodePURLchars ( component . version ) } ` ;
6
15
}
7
16
const compName = component . npmname || component . component ;
8
- return `pkg:npm/${ compName } @${ component . version } ` ;
17
+ return `pkg:npm/${ encodePURLchars ( compName ) } @${ encodePURLchars ( component . version ) } ` ;
9
18
}
0 commit comments