Skip to content

Commit

Permalink
Merge pull request #68 from ridhoq/dot-slash-valid-subpath-prefix
Browse files Browse the repository at this point in the history
Adds `./` and `../` as valid subpath prefix
  • Loading branch information
sschuberth authored Mar 4, 2024
2 parents a8ae119 + 6f82665 commit 7cb81af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packageurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ func (p *PackageURL) Normalize() error {
}
subpath := strings.Trim(p.Subpath, "/")
segs := strings.Split(p.Subpath, "/")
for _, s := range segs {
if s == "." || s == ".." {
for i, s := range segs {
if (s == "." || s == "..") && i != 0 {
return fmt.Errorf("invalid Package URL subpath: %q", p.Subpath)
}
}
Expand Down
26 changes: 26 additions & 0 deletions packageurl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,32 @@ func TestNormalize(t *testing.T) {
Subpath: "/sub/../path/",
},
wantErr: true,
}, {
name: "'./' is a valid subpath prefix",
input: packageurl.PackageURL{
Type: "npm",
Name: "pkg",
Subpath: "./sub/path",
},
want: packageurl.PackageURL{
Type: "npm",
Name: "pkg",
Qualifiers: packageurl.Qualifiers{},
Subpath: "./sub/path",
},
}, {
name: "'../' is a valid subpath prefix",
input: packageurl.PackageURL{
Type: "npm",
Name: "pkg",
Subpath: "../sub/path",
},
want: packageurl.PackageURL{
Type: "npm",
Name: "pkg",
Qualifiers: packageurl.Qualifiers{},
Subpath: "../sub/path",
},
}, {
name: "known type namespace adjustments",
input: packageurl.PackageURL{
Expand Down

0 comments on commit 7cb81af

Please sign in to comment.