mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
refactor(sanitizer): minor refactorization
Use a proper switch-case instead of a bunch of if.
This commit is contained in:
parent
89c32d518d
commit
435a950d64
1 changed files with 15 additions and 10 deletions
|
@ -312,17 +312,20 @@ func sanitizeAttributes(parsedBaseUrl *url.URL, baseURL, tagName string, attribu
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, attribute := range attributes {
|
for _, attribute := range attributes {
|
||||||
value := attribute.Val
|
|
||||||
|
|
||||||
if !isValidAttribute(tagName, attribute.Key) {
|
if !isValidAttribute(tagName, attribute.Key) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if tagName == "math" && attribute.Key == "xmlns" && value != "http://www.w3.org/1998/Math/MathML" {
|
value := attribute.Val
|
||||||
|
|
||||||
|
switch tagName {
|
||||||
|
case "math":
|
||||||
|
if attribute.Key == "xmlns" {
|
||||||
|
if value != "http://www.w3.org/1998/Math/MathML" {
|
||||||
value = "http://www.w3.org/1998/Math/MathML"
|
value = "http://www.w3.org/1998/Math/MathML"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if tagName == "img" {
|
case "img":
|
||||||
switch attribute.Key {
|
switch attribute.Key {
|
||||||
case "fetchpriority":
|
case "fetchpriority":
|
||||||
if !isValidFetchPriorityValue(value) {
|
if !isValidFetchPriorityValue(value) {
|
||||||
|
@ -336,12 +339,14 @@ func sanitizeAttributes(parsedBaseUrl *url.URL, baseURL, tagName string, attribu
|
||||||
if isImageLargerThanLayout || !isPositiveInteger(value) {
|
if isImageLargerThanLayout || !isPositiveInteger(value) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
case "srcset":
|
||||||
}
|
|
||||||
|
|
||||||
if (tagName == "img" || tagName == "source") && attribute.Key == "srcset" {
|
|
||||||
value = sanitizeSrcsetAttr(baseURL, value)
|
value = sanitizeSrcsetAttr(baseURL, value)
|
||||||
}
|
}
|
||||||
|
case "source":
|
||||||
|
if attribute.Key == "srcset" {
|
||||||
|
value = sanitizeSrcsetAttr(baseURL, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if isExternalResourceAttribute(attribute.Key) {
|
if isExternalResourceAttribute(attribute.Key) {
|
||||||
switch {
|
switch {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue