Files
Reims-Go/internal/plugin/uiassets/assets_test.go
T
千川白浪 e0ff794b0e feat: add experimental macOS desktop support on Apple Silicon (#207)
* feat: add experimental Apple Silicon support with Nivfold

Integrate the standalone Nivfold protocol 1 runner; tested against Nivfold f436fb6. The Windows Reims vGPU runtime remains independent.

* fix: open QQ invites and VM SSH on macOS

* fix: move VM, View and Help to the macOS menu bar

* feat(macos): add resumable Apple restore image downloads

Expose the compatible restore image in the VM wizard and Images page, validate downloads before caching, and fix macOS memory reporting and plugin SVG rendering.

* fix(macos): localize the native application menu

* fix(macos): address native desktop review findings
2026-12-06 00:47:07 +08:00

62 lines
1.8 KiB
Go

package uiassets
import (
"bytes"
"encoding/xml"
"io"
"testing"
)
func TestSanitizeSVGPreservesNamespacesWithoutDuplicateDeclarations(t *testing.T) {
const svg = "http://www.w3.org/2000/svg"
const xlink = "http://www.w3.org/1999/xlink"
raw := []byte(`<svg xmlns="` + svg + `" xmlns:xlink="` + xlink + `" xmlns:s="` + svg + `" viewBox="0 0 24 24">` +
`<script>foo</script><s:use xlink:href="#shape" onload="bad"/><use xlink:href="javascript:bad"/>` +
`<metadata><note xmlns=""><entry/></note></metadata><g xmlns="` + svg + `" id="shape"/></svg>`)
cleaned := SanitizeSVG(raw)
dec := xml.NewDecoder(bytes.NewReader(cleaned))
want := []xml.Name{
{Space: svg, Local: "svg"},
{Space: svg, Local: "use"},
{Space: svg, Local: "use"},
{Space: svg, Local: "metadata"},
{Local: "note"},
{Local: "entry"},
{Space: svg, Local: "g"},
}
i := 0
for {
tok, err := dec.Token()
if err == io.EOF {
break
}
if err != nil {
t.Fatalf("invalid sanitized SVG: %v\n%s", err, cleaned)
}
start, ok := tok.(xml.StartElement)
if !ok {
continue
}
if i >= len(want) || start.Name != want[i] {
t.Fatalf("unexpected element %d: %+v\n%s", i, start.Name, cleaned)
}
seen := map[xml.Name]bool{}
for _, attr := range start.Attr {
if seen[attr.Name] {
t.Fatalf("duplicate %s attribute on <%s>\n%s", attr.Name.Local, start.Name.Local, cleaned)
}
seen[attr.Name] = true
if attr.Name.Local == "onload" || (attr.Name.Local == "href" && (i != 1 || attr.Name.Space != xlink || attr.Value != "#shape")) {
t.Fatalf("unexpected attribute on <%s>: %+v", start.Name.Local, attr)
}
}
if i == 1 && !seen[xml.Name{Space: xlink, Local: "href"}] {
t.Fatal("lost local namespaced reference")
}
i++
}
if i != len(want) {
t.Fatalf("found %d elements, want %d: %s", i, len(want), cleaned)
}
}