Просмотр исходного кода

refactor(sanitizer): don't process tags when len(blockedStack) != 0

Then there are things in blockedStack, it means that we're currently iterating
on children of a blocked tag, so there is no need to actually process them.
jvoisin 5 месяцев назад
Родитель
Сommit
8357e6decf
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      internal/reader/sanitizer/sanitizer.go

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

@@ -253,6 +253,10 @@ func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) s
 
 
 			buffer.WriteString(token.String())
 			buffer.WriteString(token.String())
 		case html.StartTagToken:
 		case html.StartTagToken:
+			if len(blockedStack) != 0 {
+				continue
+			}
+
 			parentTag = tagName
 			parentTag = tagName
 
 
 			if isPixelTracker(tagName, token.Attr) {
 			if isPixelTracker(tagName, token.Attr) {
@@ -264,7 +268,7 @@ func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) s
 				continue
 				continue
 			}
 			}
 
 
-			if len(blockedStack) == 0 && isValidTag(tagName) {
+			if isAllowedTag(tagName) {
 				attrNames, htmlAttributes := sanitizeAttributes(parsedBaseUrl, tagName, token.Attr, sanitizerOptions)
 				attrNames, htmlAttributes := sanitizeAttributes(parsedBaseUrl, tagName, token.Attr, sanitizerOptions)
 				if hasRequiredAttributes(tagName, attrNames) {
 				if hasRequiredAttributes(tagName, attrNames) {
 					if len(attrNames) > 0 {
 					if len(attrNames) > 0 {