diff --git a/htmltest/check-link_test.go b/htmltest/check-link_test.go index 7a87a2a..c173fb1 100644 --- a/htmltest/check-link_test.go +++ b/htmltest/check-link_test.go @@ -282,6 +282,28 @@ func TestAnchorExternalInvalidBrackets(t *testing.T) { tExpectIssue(t, hT, "bad reference", 1) } +func TestAnchorExternalQueryStringDefault(t *testing.T) { + // passes when ignoring from default list of query string exempt URLs + hT := tTestFile("fixtures/links/query_strings.html") + tExpectIssueCount(t, hT, 0) +} + +func TestAnchorExternalQueryStripQueryExcludesEmpty(t *testing.T) { + // fails when StripQueryExcludes blank and URL doesn't like query string hits + hT := tTestFileOpts("fixtures/links/query_strings.html", + map[string]interface{}{"StripQueryExcludes": []interface{}{}}) + tExpectIssueCount(t, hT, 1) + tExpectIssue(t, hT, "Non-OK status: 400", 1) +} + +func TestAnchorExternalQueryStringStripQueryExcludesDiffers(t *testing.T) { + // fails when StripQueryExcludes does not include URL and URL doesn't like query string hits + hT := tTestFileOpts("fixtures/links/query_strings.html", + map[string]interface{}{"StripQueryExcludes": []interface{}{"example.com", "test.invalid"}}) + tExpectIssueCount(t, hT, 1) + tExpectIssue(t, hT, "Non-OK status: 400", 1) +} + func TestAnchorInternalBroken(t *testing.T) { // fails for broken internal links hT := tTestFile("fixtures/links/brokenLinkInternal.html") diff --git a/htmltest/fixtures/links/query_strings.html b/htmltest/fixtures/links/query_strings.html new file mode 100644 index 0000000..b5f8ce2 --- /dev/null +++ b/htmltest/fixtures/links/query_strings.html @@ -0,0 +1,11 @@ + + + + + Title + + + + + + diff --git a/htmltest/options.go b/htmltest/options.go index e497cf7..2a53a72 100644 --- a/htmltest/options.go +++ b/htmltest/options.go @@ -61,7 +61,7 @@ type Options struct { ExternalTimeout int StripQueryString bool - StripQueryExcludes []string + StripQueryExcludes []interface{} EnableCache bool EnableLog bool @@ -128,7 +128,7 @@ func DefaultOptions() map[string]interface{} { "ExternalTimeout": 15, "StripQueryString": true, - "StripQueryExcludes": []string{"fonts.googleapis.com"}, + "StripQueryExcludes": []interface{}{"fonts.googleapis.com"}, "EnableCache": true, "EnableLog": true, @@ -164,9 +164,9 @@ func (hT *HTMLTest) setOptions(optsUser map[string]interface{}) { } // InList tests if key is in a slice/list. -func InList(list []string, key string) bool { +func InList(list []interface{}, key string) bool { for _, item := range list { - if strings.Contains(key, item) { + if strings.Contains(key, fmt.Sprintf("%s", item)) { return true } } diff --git a/htmltest/options_test.go b/htmltest/options_test.go index 2cc4da5..c3b7db3 100644 --- a/htmltest/options_test.go +++ b/htmltest/options_test.go @@ -34,7 +34,7 @@ func TestSetOptions(t *testing.T) { } func TestInList(t *testing.T) { - lst := []string{"alpha", "bravo", "charlie"} + lst := []interface{}{"alpha", "bravo", "charlie"} assert.Equals(t, "alpha in lst", InList(lst, "alpha"), true) assert.Equals(t, "bravo in lst", InList(lst, "bravo"), true) assert.Equals(t, "charlie in lst", InList(lst, "charlie"), true)