why can't svg just be normal?
Ted Unangst tedu@tedunangst.com
Thu, 07 Dec 2023 18:19:39 -0500
1 files changed,
10 insertions(+),
2 deletions(-)
jump to
M
backend.go
→
backend.go
@@ -69,8 +69,16 @@ data = data[3:]
} ct := http.DetectContentType(data) if strings.HasPrefix(ct, "text/xml") || strings.HasPrefix(ct, "text/plain") { - if bytes.HasPrefix(data, []byte("<svg ")) || bytes.HasPrefix(data, []byte("<!DOCTYPE svg PUBLIC")) { - return true + // this seems suboptimal + prefixes := []string{ + `<svg `, + `<!DOCTYPE svg PUBLIC`, + `<?xml version="1.0" encoding="UTF-8"?> <svg `, + } + for _, pre := range prefixes { + if bytes.HasPrefix(data, []byte(pre)) { + return true + } } } return ct == "image/svg+xml"