Do not URL-safe encode the namespace. PackageURL does this
This commit is contained in:
Vendored
+1
-2
@@ -108,8 +108,7 @@ function parseGoPackage(pkg) {
|
|||||||
let namespace = null;
|
let namespace = null;
|
||||||
let name;
|
let name;
|
||||||
if (qualifiedPackage.indexOf('/') !== -1) {
|
if (qualifiedPackage.indexOf('/') !== -1) {
|
||||||
// need to URL-safe encode slashes in the namespace
|
namespace = path_1.default.dirname(qualifiedPackage);
|
||||||
namespace = encodeURIComponent(path_1.default.dirname(qualifiedPackage));
|
|
||||||
name = path_1.default.basename(qualifiedPackage);
|
name = path_1.default.basename(qualifiedPackage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+10
-13
@@ -12,12 +12,9 @@ describe('parseGoPackage', () => {
|
|||||||
'pkg:golang/foo/[email protected]'
|
'pkg:golang/foo/[email protected]'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
// this test should pass, but packageurl-js is double URL-safe encoding the
|
it('parses a package with a namespace with slashes', () => {
|
||||||
// '%' to %25. It won't, however, URL-encode the '/' that is represented by
|
expect(parseGoPackage('github.com/foo/[email protected]').toString()).toEqual(
|
||||||
// %2F.
|
'pkg:golang/github.com/foo/[email protected]'
|
||||||
it.skip('parses a package with a namespace with slashes', () => {
|
|
||||||
expect(parseGoPackage('foo/boo/[email protected]').toString()).toEqual(
|
|
||||||
'pkg:golang/foo%2Fboo/[email protected]'
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
it('parses a package without a namespace', () => {
|
it('parses a package without a namespace', () => {
|
||||||
@@ -36,7 +33,7 @@ describe('parseGoList', () => {
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'otlptracehttp',
|
name: 'otlptracehttp',
|
||||||
namespace: 'go.opentelemetry.io%2Fotel%2Fexporters%2Fotlp%2Fotlptrace',
|
namespace: 'go.opentelemetry.io/otel/exporters/otlp/otlptrace',
|
||||||
version: 'v1.7.0',
|
version: 'v1.7.0',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
@@ -44,7 +41,7 @@ describe('parseGoList', () => {
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'sys',
|
name: 'sys',
|
||||||
namespace: 'golang.org%2Fx',
|
namespace: 'golang.org/x',
|
||||||
version: 'v0.0.0-20220317061510-51cd9980dadf',
|
version: 'v0.0.0-20220317061510-51cd9980dadf',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
@@ -52,7 +49,7 @@ describe('parseGoList', () => {
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'text',
|
name: 'text',
|
||||||
namespace: 'golang.org%2Fx',
|
namespace: 'golang.org/x',
|
||||||
version: 'v0.3.7',
|
version: 'v0.3.7',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
@@ -88,7 +85,7 @@ github.com/mattn/[email protected] github.com/mattn/[email protected]`)
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'color',
|
name: 'color',
|
||||||
namespace: 'github.com%2Ffatih',
|
namespace: 'github.com/fatih',
|
||||||
version: 'v1.13.0',
|
version: 'v1.13.0',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
@@ -96,7 +93,7 @@ github.com/mattn/[email protected] github.com/mattn/[email protected]`)
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'go-isatty',
|
name: 'go-isatty',
|
||||||
namespace: 'github.com%2Fmattn',
|
namespace: 'github.com/mattn',
|
||||||
version: 'v0.0.14',
|
version: 'v0.0.14',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
@@ -106,7 +103,7 @@ github.com/mattn/[email protected] github.com/mattn/[email protected]`)
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'go-colorable',
|
name: 'go-colorable',
|
||||||
namespace: 'github.com%2Fmattn',
|
namespace: 'github.com/mattn',
|
||||||
version: 'v1.1.9',
|
version: 'v1.1.9',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
@@ -114,7 +111,7 @@ github.com/mattn/[email protected] github.com/mattn/[email protected]`)
|
|||||||
{
|
{
|
||||||
type: 'golang',
|
type: 'golang',
|
||||||
name: 'go-isatty',
|
name: 'go-isatty',
|
||||||
namespace: 'github.com%2Fmattn',
|
namespace: 'github.com/mattn',
|
||||||
version: 'v0.0.12',
|
version: 'v0.0.12',
|
||||||
qualifiers: null,
|
qualifiers: null,
|
||||||
subpath: null
|
subpath: null
|
||||||
|
|||||||
+1
-2
@@ -6,8 +6,7 @@ export function parseGoPackage (pkg: string): PackageURL {
|
|||||||
let namespace: string | null = null
|
let namespace: string | null = null
|
||||||
let name: string
|
let name: string
|
||||||
if (qualifiedPackage.indexOf('/') !== -1) {
|
if (qualifiedPackage.indexOf('/') !== -1) {
|
||||||
// need to URL-safe encode slashes in the namespace
|
namespace = path.dirname(qualifiedPackage)
|
||||||
namespace = encodeURIComponent(path.dirname(qualifiedPackage))
|
|
||||||
name = path.basename(qualifiedPackage)
|
name = path.basename(qualifiedPackage)
|
||||||
} else {
|
} else {
|
||||||
name = qualifiedPackage
|
name = qualifiedPackage
|
||||||
|
|||||||
Reference in New Issue
Block a user