aboutsummaryrefslogtreecommitdiff
path: root/html.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-16 14:40:53 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-16 14:40:53 +0100
commit2747bd581e1bae0a1436fcde984558304c005333 (patch)
treea9ddc0dde8b4a17896e9dafb86b2906ed3104b19 /html.go
parenta75ea9362403a4d9da13bca2e3c1a44814723f0b (diff)
fix(html): invalid parsing of argumentsHEADmain
Diffstat (limited to 'html.go')
-rw-r--r--html.go70
1 files changed, 54 insertions, 16 deletions
diff --git a/html.go b/html.go
index 52460ee..463e1f3 100644
--- a/html.go
+++ b/html.go
@@ -97,33 +97,71 @@ func parseArgs(base string) map[string]string {
var key strings.Builder
var value strings.Builder
var quote bool
- for i < len(content) && content[i] != '>' && (i+1 == len(content) || string(content[i:i+2]) != "/>") {
+ next := true
+ finish := func() {
+ quote = false
+ sep = false
+ if key.Len() > 0 {
+ res[key.String()] = value.String()
+ }
+ key.Reset()
+ value.Reset()
+ }
+ for i < len(content) && next {
curr := content[i]
if !sep {
switch curr {
case '=':
sep = true
- case ' ':
- sep = false
- if key.Len() > 0 {
- res[key.String()] = ""
+ case '/':
+ if i+1 >= len(content) || string(content[i:i+2]) != "/>" {
+ key.WriteRune(curr)
+ i++
+ continue
}
- key.Reset()
+ fallthrough
+ case '>':
+ next = false
+ fallthrough
+ case ' ':
+ finish()
default:
key.WriteRune(curr)
}
} else {
- if value.Len() == 0 && curr == '"' {
- quote = true
- } else if (curr == '"' && quote) || curr == ' ' && !quote {
- quote = false
- sep = false
- res[key.String()] = value.String()
- key.Reset()
- value.Reset()
- } else {
- value.WriteRune(curr)
+ switch curr {
+ case '"':
+ if value.Len() == 0 {
+ quote = true
+ i++
+ continue
+ } else if quote {
+ finish()
+ i++
+ continue
+ }
+ case '/':
+ if i+1 >= len(content) || string(content[i:i+2]) != "/>" {
+ value.WriteRune(curr)
+ i++
+ continue
+ }
+ fallthrough
+ case '>':
+ if !quote {
+ next = false
+ }
+ fallthrough
+ case ' ':
+ if !quote {
+ finish()
+ i++
+ continue
+ }
+ fallthrough
+ default:
}
+ value.WriteRune(curr)
}
i++
}