Browse Source

refactor(sanitizer): html attributes keys are always lowercase

jvoisin 2 months ago
parent
commit
62f316c7cf

+ 1 - 1
internal/reader/sanitizer/sanitizer.go

@@ -239,7 +239,7 @@ func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) s
 
 
 func isHidden(n *html.Node) bool {
 func isHidden(n *html.Node) bool {
 	for _, attr := range n.Attr {
 	for _, attr := range n.Attr {
-		if strings.ToLower(attr.Key) == "hidden" {
+		if attr.Key == "hidden" {
 			return true
 			return true
 		}
 		}
 	}
 	}

+ 10 - 0
internal/reader/sanitizer/sanitizer_test.go

@@ -1021,3 +1021,13 @@ func TestBlockedResourcesSubstrings(t *testing.T) {
 		t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
 		t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
 	}
 	}
 }
 }
+
+func TestAttrLowerCase(t *testing.T) {
+	input := `<a HrEF="http://example.com" HIddEN>test</a>`
+	expected := ``
+	output := sanitizeHTMLWithDefaultOptions("http://example.org/", input)
+
+	if expected != output {
+		t.Errorf(`Wrong output: "%s" != "%s"`, expected, output)
+	}
+}