From 6c839f615719953bc0be730e79d3725afa4cf835 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 6 May 2017 01:35:55 +0900 Subject: [PATCH] Fix not to include rel in params --- main.go | 5 ++--- main_test.go | 16 +++++----------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 57b8c17..d61af11 100644 --- a/main.go +++ b/main.go @@ -108,10 +108,9 @@ func Parse(raw string) Links { // Special case for rel if strings.ToLower(key) == "rel" { link.Rel = val + } else { + link.Params[key] = val } - - link.Params[key] = val - } if link.URL != "" { diff --git a/main_test.go b/main_test.go index 2d75426..05a8d36 100644 --- a/main_test.go +++ b/main_test.go @@ -1,8 +1,6 @@ package linkheader -import ( - "testing" -) +import "testing" func TestSimple(t *testing.T) { // 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\"") } - if len(links[0].Params) != 1 { - t.Errorf("First link should have exactly 1 params, but has %d", len(links[0].Params)) + if len(links[0].Params) != 0 { + t.Errorf("First link should have exactly 0 params, but has %d", len(links[0].Params)) } - if len(links[1].Params) != 2 { - t.Errorf("Second link should have exactly 2 params, but has %d", len(links[1].Params)) + if len(links[1].Params) != 1 { + t.Errorf("Second link should have exactly 1 params, but has %d", len(links[1].Params)) } if links[1].Params["pet"] != "cat" { @@ -64,10 +62,6 @@ func TestLinkMethods(t *testing.T) { links := Parse(header) link := links[0] - if !link.HasParam("rel") { - t.Errorf("Link should have param 'rel'") - } - if link.HasParam("foo") { t.Errorf("Link should not have param 'foo'") }