From 39ea6e42865402f640a95fb3475cfddfc0a235d6 Mon Sep 17 00:00:00 2001 From: Adrien Duermael Date: Tue, 13 Dec 2016 13:15:18 -0800 Subject: [PATCH] look for absolute links to docs.docker.com Signed-off-by: Adrien Duermael --- tests/src/validator/html_test.go | 34 +++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tests/src/validator/html_test.go b/tests/src/validator/html_test.go index 5d71312eef..6050cb45ce 100644 --- a/tests/src/validator/html_test.go +++ b/tests/src/validator/html_test.go @@ -66,44 +66,38 @@ func testURLs(htmlBytes []byte) error { return nil case html.StartTagToken: t := z.Token() + + url := "" + // check tag types switch t.Data { case "a": countLinks++ - ok, _ := getHref(t) + ok, href := getHref(t) // skip, it may just be an anchor if !ok { break } + url = href case "img": countImages++ - ok, _ := getSrc(t) + ok, src := getSrc(t) if !ok { return errors.New("img with no src: " + t.String()) } + url = src + } + + // there's an url to test! + if url != "" { + if strings.Contains(url, "docs.docker.com") { + return errors.New("found absolute link: " + t.String()) + } } } } - // _, md, err := frontparser.ParseFrontmatterAndContent(mdBytes) - // if err != nil { - // return err - // } - - // regularExpression, err := regexp.Compile(`\[[^\]]+\]\(([^\)]+)\)`) - // if err != nil { - // return err - // } - - // submatches := regularExpression.FindAllStringSubmatch(string(md), -1) - - // for _, submatch := range submatches { - // if strings.Contains(submatch[1], "docs.docker.com") { - // return errors.New("found absolute link (" + strings.TrimSpace(submatch[1]) + ")") - // } - // } - return nil }