Skip to content

Commit

Permalink
XML: keep all spaces inside CDATA, fixes #722
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jul 4, 2024
1 parent 03662c3 commit d07e07f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion xml/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]st
if len(t.Text) == 0 {
continue
} else if text, useText := xml.EscapeCDATAVal(&attrByteBuffer, t.Text); useText {
t.TokenType = xml.TextToken
t.Data = text
}
}
Expand Down
5 changes: 4 additions & 1 deletion xml/xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestXML(t *testing.T) {
{`<A>x</A>`, `<A>x</A>`},
{`<a><b>x</b></a>`, `<a><b>x</b></a>`},
{"<a><b>x\ny</b></a>", "<a><b>x\ny</b></a>"},
{`<a> <![CDATA[ a ]]> </a>`, `<a>a</a>`},
{`<a> <![CDATA[ a ]]> </a>`, `<a> a </a>`},
{`<a >a</a >`, `<a>a</a>`},
{`<?xml version="1.0" ?>`, `<?xml version="1.0"?>`},
{`<x></x>`, `<x/>`},
Expand Down Expand Up @@ -75,7 +75,10 @@ func TestXMLKeepWhitespace(t *testing.T) {
{`<x> <![CDATA[ x ]]> </x>`, `<x> x </x>`},
{`<x> <![CDATA[ <<<<< ]]> </x>`, `<x><![CDATA[ <<<<< ]]></x>`},

{` <![CDATA[ %d ]]> `, ` %d `}, // #722
{`<a><![CDATA[ %d ]]></a>`, `<a> %d </a>`}, // #722
{`<a><![CDATA[ %d ]]><b>`, `<a> %d <b>`}, // #722
{`<a> %d <b>`, `<a> %d <b>`}, // #722
}

m := minify.New()
Expand Down

0 comments on commit d07e07f

Please sign in to comment.