From 434783165bbdd6adfd1084f6790d370634757d82 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Thu, 17 Oct 2024 05:18:02 +0200 Subject: [PATCH] Add needed checks for link if attributes are empty --- link.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/link.go b/link.go index 3b83214..e369703 100644 --- a/link.go +++ b/link.go @@ -38,16 +38,22 @@ func (l *Link) Check() error { } } - if strings.Contains(l.Rel, ":") && !isValidIRI(IRI(l.Rel)) { - return fmt.Errorf("rel attribute %v of link %v not correctly formatted", l.Rel, l.Href) + if l.Rel != "" { + if strings.Contains(l.Rel, ":") && !isValidIRI(IRI(l.Rel)) { + return fmt.Errorf("rel attribute %v of link %v not correctly formatted", l.Rel, l.Href) + } } - if !isValidMediaType(string(l.Type)) { - return fmt.Errorf("type attribute %v of link %v invalid media type", l.Type, l.Href) + if l.Type != "" { + if !isValidMediaType(string(l.Type)) { + return fmt.Errorf("type attribute %v of link %v invalid media type", l.Type, l.Href) + } } - if !isValidLanguageTag(l.HrefLang) { - return fmt.Errorf("hreflang attribute %v of link %v invalid language tag", l.Type, l.HrefLang) + if l.HrefLang != "" { + if !isValidLanguageTag(l.HrefLang) { + return fmt.Errorf("hreflang attribute %v of link %v invalid language tag", l.Type, l.HrefLang) + } } if l.Content == nil {