From 88d7f672b834576fb0022fe6d3ac985a0be0b38e Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 21 Nov 2017 17:56:52 +0900 Subject: [PATCH] Ignore id links --- examples/html.feature | 18 ++++++++++++++++++ file_checker.go | 5 +++++ file_checker_test.go | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/html.feature b/examples/html.feature index ae4d07d..16a712b 100644 --- a/examples/html.feature +++ b/examples/html.feature @@ -22,3 +22,21 @@ Feature: HTML """ When I successfully run `liche foo.html` Then the stderr should contain exactly "" + + Scenario: Ignore id reference + Given a file named "foo.html" with: + """ + + + + My title + + +
+ Google +
+ + + """ + When I successfully run `liche foo.html` + Then the stderr should contain exactly "" diff --git a/file_checker.go b/file_checker.go index fe642d7..c2a1720 100644 --- a/file_checker.go +++ b/file_checker.go @@ -4,6 +4,7 @@ import ( "bytes" "io/ioutil" "net/url" + "strings" "sync" "time" @@ -118,6 +119,10 @@ func extractURLs(n *html.Node) []string { } func isURL(s string) bool { + if strings.HasPrefix(s, "#") { + return false + } + u, err := url.Parse(s) return err == nil && (u.Scheme == "" || u.Scheme == "http" || u.Scheme == "https") } diff --git a/file_checker_test.go b/file_checker_test.go index 7adc17b..13d8ed7 100644 --- a/file_checker_test.go +++ b/file_checker_test.go @@ -53,7 +53,7 @@ func TestIsURL(t *testing.T) { assert.True(t, isURL(s)) } - for _, s := range []string{"ftp://foo.com", "file://file-path"} { + for _, s := range []string{"ftp://foo.com", "file://file-path", "#foo"} { assert.False(t, isURL(s)) } }