MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestEntityReplacement

Function TestEntityReplacement

xmlparser/document_test.go:58–101  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

56}
57
58func TestEntityReplacement(t *testing.T) {
59 svgData := []byte(`<?xml version="1.0"?>
60<!DOCTYPE svg [
61 <!ENTITY myEntity1 "EntityValue1">
62 <!ENTITY myEntity2 'EntityValue2'>
63]>
64<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
65 <text x="10" y="20" arg1="Value with &myEntity1;" arg2='&myEntity2;'>
66 &myEntity1; and &myEntity2;
67 </text>
68 <style>
69 <![CDATA[
70 .textClass { content: "&myEntity1;"; }
71 ]]>
72 </style>
73</svg>`)
74
75 expectedData := []byte(`<?xml version="1.0"?>
76<!DOCTYPE svg [
77 <!ENTITY myEntity1 "EntityValue1">
78 <!ENTITY myEntity2 'EntityValue2'>
79]>
80<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
81 <text x="10" y="20" arg1="Value with EntityValue1" arg2="EntityValue2">
82 EntityValue1 and EntityValue2
83 </text>
84 <style>
85 <![CDATA[
86 .textClass { content: "&myEntity1;"; }
87 ]]>
88 </style>
89</svg>`)
90
91 doc, err := xmlparser.NewDocument(bytes.NewReader(svgData))
92 require.NoError(t, err)
93
94 doc.ReplaceEntities()
95
96 var buf bytes.Buffer
97 err = doc.WriteTo(&buf)
98 require.NoError(t, err)
99
100 require.Equal(t, string(expectedData), buf.String())
101}
102
103func BenchmarkDocumentParsing(b *testing.B) {
104 testImagesPath, err := filepath.Abs("../testdata/test-images/svg-test-suite")

Callers

nothing calls this directly

Calls 4

ReplaceEntitiesMethod · 0.95
NewDocumentFunction · 0.92
WriteToMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected