Преглед изворни кода

refactor(sanitizer): html attributes keys are always lowercase

jvoisin пре 2 месеци
родитељ
комит
62f316c7cf
2 измењених фајлова са 11 додато и 1 уклоњено
  1. 1 1
      internal/reader/sanitizer/sanitizer.go
  2. 10 0
      internal/reader/sanitizer/sanitizer_test.go

+ 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 {
 	for _, attr := range n.Attr {
-		if strings.ToLower(attr.Key) == "hidden" {
+		if attr.Key == "hidden" {
 			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)
 	}
 }
+
+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)
+	}
+}