shithub: mycel

Download patch

ref: e1e71dec97f88d1fdefd5615368485c373c75f79
parent: f26be72083a16563f20142e02e59e0d4c662f6c1
author: Philip Silva <philip.silva@protonmail.com>
date: Wed Jan 26 09:59:11 EST 2022

single quotes in svgs

--- a/img/img.go
+++ b/img/img.go
@@ -16,10 +16,10 @@
 	"net/url"
 	"strings"
 
+	_ "golang.org/x/image/webp"
 	_ "image/gif"
 	_ "image/jpeg"
 	_ "image/png"
-	_ "golang.org/x/image/webp"
 )
 
 const SrcZero = "//:0"
@@ -106,6 +106,7 @@
 }
 
 func quoteAttrs(s string) string {
+	s = strings.ReplaceAll(s, `'`, `"`)
 	if strings.Contains(s, `"`) {
 		return s
 	}
@@ -150,7 +151,7 @@
 	return s
 }
 
-// Svg returns the svg+xml encoded as jpg with the sizing defined in
+// Svg returns the svg+xml with the sizing defined in
 // viewbox unless w and h != 0
 func Svg(dui *duit.DUI, data string, w, h int) (ni *draw.Image, err error) {
 	rgba, err := svg(data, w, h)
--- a/img/img_test.go
+++ b/img/img_test.go
@@ -2,6 +2,7 @@
 
 import (
 	"bytes"
+	"context"
 	"github.com/psilva261/opossum"
 	"github.com/psilva261/opossum/logger"
 	"image"
@@ -21,6 +22,8 @@
 		"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50' %3e%3cpath d='M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z'/%3e %3c/svg%3e",
 		"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MCA1MCI+PHBhdGggZD0iTTIyIDM4VjUxTDMyIDMybDE5LTE5djEyQzQ0IDI2IDQzIDEwIDM4IDAgNTIgMTUgNDkgMzkgMjIgMzh6Ii8+PC9zdmc+",
 		`data:image/svg+xml;charset=utf-8,%3Csvg xmlns=http://www.w3.org/2000/svg%3E%3C/svg%3E`,
+		// additional example
+		`data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 30' width='20' height='30' %3E%3C/svg%3E`,
 	}
 
 	for _, src := range srcs {
@@ -28,7 +31,7 @@
 		if err != nil {
 			t.Fatalf(err.Error())
 		}
-		t.Logf("%v", data)
+		t.Logf("%v", string(data))
 	}
 }
 
@@ -41,14 +44,22 @@
 }
 
 func TestSvg(t *testing.T) {
-	xml := `
+	xmls := []string{
+		`
                <svg fill="currentColor" height="24" viewBox="0 0 24 24" width="24">
                </svg>
-       `
+       `,
+		`
+               <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 30' width='20' height='30'>
+               </svg>
+       `,
+	}
 
-	_, err := svg(xml, 0, 0)
-	if err != nil {
-		t.Fatalf(err.Error())
+	for _, xml := range xmls {
+		_, err := svg(xml, 0, 0)
+		if err != nil {
+			t.Fatalf(err.Error())
+		}
 	}
 }
 
@@ -83,6 +94,10 @@
 
 type MockBrowser struct {
 	data []byte
+}
+
+func (b *MockBrowser) Ctx() context.Context {
+	return context.Background()
 }
 
 func (b *MockBrowser) Origin() *url.URL { return nil }
--- a/style/css.go
+++ b/style/css.go
@@ -11,6 +11,9 @@
 	"strings"
 )
 
+// Sheet represents a stylesheet with rules.
+//
+// structs inspired by now discontinued github.com/aymerick/douceur
 type Sheet struct {
 	Rules []Rule
 }