Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qualifier values do not have first character converted to lowercase #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packageurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,14 @@ func parseQualifiers(rawQuery string) (Qualifiers, error) {
return nil, fmt.Errorf("invalid qualifier key: '%s'", key)
}

value, err = url.QueryUnescape(value)
if err != nil {
return nil, fmt.Errorf("error unescaping qualifier value %q", value)
}

q = append(q, Qualifier{
Key: strings.ToLower(key),
if len(value) > 0 {
// only the first character needs to be lowercase. Note that pURL is always UTF8, so we
// don't need to care about unicode here.
Value: strings.ToLower(value[:1]) + value[1:],
value = strings.ToLower(value[:1]) + value[1:]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not even sure the lowercase first character is needed. I can't see it specified in the spec.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tommyknows Hey Ramon, do you know if we really need lowercase characters here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, I thought this was just the behaviour I ported from before the refactor, but I actually can't seem to find that 👀

i wonder why I've added it in that case...

Also, it's not in the spec and I can't see any test cases requiring this. I'd say remove it then...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favour of removing the lowercase conversion. I updated the title of the pull request and added another commit to just remove the case conversion.

}
q = append(q, Qualifier{
Key: strings.ToLower(key),
Value: value,
})
}
return q, nil
Expand Down
16 changes: 16 additions & 0 deletions packageurl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,19 @@ func TestNameEscaping(t *testing.T) {
}

}

func TestQualifierMissingEqual(t *testing.T) {
input := "pkg:npm/test-pkg?key"
want := packageurl.PackageURL{
Type: "npm",
Name: "test-pkg",
Qualifiers: packageurl.Qualifiers{{Key: "key"}},
}
got, err := packageurl.FromString(input)
if err != nil {
t.Fatalf("FromString(%s): unexpected error: %v", input, err)
}
if !reflect.DeepEqual(want, got) {
t.Fatalf("FromString(%s): want %q got %q", input, want, got)
}
}