Fix not to include rel in params

This commit is contained in:
178inaba 2017-05-06 01:35:55 +09:00
parent ee06f2596c
commit 6c839f6157
2 changed files with 7 additions and 14 deletions

View File

@ -108,10 +108,9 @@ func Parse(raw string) Links {
// Special case for rel // Special case for rel
if strings.ToLower(key) == "rel" { if strings.ToLower(key) == "rel" {
link.Rel = val link.Rel = val
} } else {
link.Params[key] = val link.Params[key] = val
}
} }
if link.URL != "" { if link.URL != "" {

View File

@ -1,8 +1,6 @@
package linkheader package linkheader
import ( import "testing"
"testing"
)
func TestSimple(t *testing.T) { func TestSimple(t *testing.T) {
// Test case stolen from https://github.com/thlorenz/parse-link-header :) // Test case stolen from https://github.com/thlorenz/parse-link-header :)
@ -24,12 +22,12 @@ func TestSimple(t *testing.T) {
t.Errorf("First link should have rel=\"next\"") t.Errorf("First link should have rel=\"next\"")
} }
if len(links[0].Params) != 1 { if len(links[0].Params) != 0 {
t.Errorf("First link should have exactly 1 params, but has %d", len(links[0].Params)) t.Errorf("First link should have exactly 0 params, but has %d", len(links[0].Params))
} }
if len(links[1].Params) != 2 { if len(links[1].Params) != 1 {
t.Errorf("Second link should have exactly 2 params, but has %d", len(links[1].Params)) t.Errorf("Second link should have exactly 1 params, but has %d", len(links[1].Params))
} }
if links[1].Params["pet"] != "cat" { if links[1].Params["pet"] != "cat" {
@ -64,10 +62,6 @@ func TestLinkMethods(t *testing.T) {
links := Parse(header) links := Parse(header)
link := links[0] link := links[0]
if !link.HasParam("rel") {
t.Errorf("Link should have param 'rel'")
}
if link.HasParam("foo") { if link.HasParam("foo") {
t.Errorf("Link should not have param 'foo'") t.Errorf("Link should not have param 'foo'")
} }