Merge pull request #1 from tomnomnom/empty-string-fixes
Fixes links with no rel attribute; removes old Go versions from travis
This commit is contained in:
commit
24cc489bfd
10
.travis.yml
10
.travis.yml
|
@ -1,14 +1,6 @@
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.5
|
|
||||||
- 1.6
|
- 1.6
|
||||||
|
- 1.7
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
install:
|
|
||||||
- ./script/bootstrap
|
|
||||||
|
|
||||||
script:
|
|
||||||
- ./script/test
|
|
||||||
# - ./script/lint
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Golang Link Header Parser
|
# Golang Link Header Parser
|
||||||
|
|
||||||
Library for parsing HTTP Link headers. Requires Go 1.2 or higher.
|
Library for parsing HTTP Link headers. Requires Go 1.6 or higher.
|
||||||
|
|
||||||
Docs can be found on [the GoDoc page](https://godoc.org/github.com/tomnomnom/linkheader).
|
Docs can be found on [the GoDoc page](https://godoc.org/github.com/tomnomnom/linkheader).
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -114,7 +114,7 @@ func Parse(raw string) Links {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if link.URL != "" && link.Rel != "" {
|
if link.URL != "" {
|
||||||
links = append(links, link)
|
links = append(links, link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
main_test.go
14
main_test.go
|
@ -45,6 +45,20 @@ func TestEmpty(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Although not often seen in the wild, the grammar in RFC 5988 suggests that it's
|
||||||
|
// valid for a link header to have nothing but a URL.
|
||||||
|
func TestNoRel(t *testing.T) {
|
||||||
|
links := Parse("<http://example.com>")
|
||||||
|
|
||||||
|
if len(links) != 1 {
|
||||||
|
t.Fatalf("Length of links should be 1, but was %d", len(links))
|
||||||
|
}
|
||||||
|
|
||||||
|
if links[0].URL != "http://example.com" {
|
||||||
|
t.Errorf("URL should be http://example.com, but was %s", links[0].URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLinkMethods(t *testing.T) {
|
func TestLinkMethods(t *testing.T) {
|
||||||
header := "<https://api.github.com/user/9287/repos?page=1&per_page=100>; rel=\"prev\"; pet=\"cat\""
|
header := "<https://api.github.com/user/9287/repos?page=1&per_page=100>; rel=\"prev\"; pet=\"cat\""
|
||||||
links := Parse(header)
|
links := Parse(header)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user