From a2702e7449e04ec7ce90428fbc707d8293eca27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytautas=20=C5=A0altenis?= Date: Sat, 11 Apr 2015 18:06:30 +0300 Subject: [PATCH] Simplify isRelativeLink() a bit --- html.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/html.go b/html.go index ba10825..3655a10 100644 --- a/html.go +++ b/html.go @@ -874,34 +874,32 @@ func doubleSpace(out *bytes.Buffer) { } func isRelativeLink(link []byte) (yes bool) { - yes = false - // a tag begin with '#' if link[0] == '#' { - yes = true + return true } // link begin with '/' but not '//', the second maybe a protocol relative link if len(link) >= 2 && link[0] == '/' && link[1] != '/' { - yes = true + return true } // only the root '/' if len(link) == 1 && link[0] == '/' { - yes = true + return true } // current directory : begin with "./" - if len(link) >= 2 && link[0] == '.' && link[1] == '/' { - yes = true + if bytes.HasPrefix(link, []byte("./")) { + return true } // parent directory : begin with "../" - if len(link) >= 3 && link[0] == '.' && link[1] == '.' && link[2] == '/' { - yes = true + if bytes.HasPrefix(link, []byte("../")) { + return true } - return + return false } func (options *Html) ensureUniqueHeaderID(id string) string {