@@ -280,6 +280,53 @@ func TestEscapeOutputValue(t *testing.T) {
280280
281281}
282282
283+ func TestUnnecessaryEscapeOutputValue (t * testing.T ) {
284+ data := `<?xml version="1.0" encoding="utf-8"?>
285+ <class_list xml:space="preserve">
286+ <student>
287+ <name> Robert </name>
288+ <grade>A+</grade>
289+
290+ </student>
291+ </class_list>`
292+
293+ root , err := Parse (strings .NewReader (data ))
294+ if err != nil {
295+ t .Error (err )
296+ }
297+
298+ escapedInnerText := root .OutputXML (true )
299+ if strings .Contains (escapedInnerText , "	" ) {
300+ t .Fatal ("\\ n has been escaped unnecessarily" )
301+ }
302+
303+ if strings .Contains (escapedInnerText , "
" ) {
304+ t .Fatal ("\\ t has been escaped unnecessarily" )
305+ }
306+
307+ }
308+
309+ func TestHtmlUnescapeStringOriginString (t * testing.T ) {
310+ // has escape html character and \t
311+ data := `<?xml version="1.0" encoding="utf-8"?>
312+ <example xml:space="preserve"><word>&#48; </word></example>`
313+
314+ root , err := Parse (strings .NewReader (data ))
315+ if err != nil {
316+ t .Error (err )
317+ }
318+
319+ escapedInnerText := root .OutputXML (false )
320+ unescapeString := html .UnescapeString (escapedInnerText )
321+ if strings .Contains (unescapeString , "&" ) {
322+ t .Fatal ("& need unescape" )
323+ }
324+ if ! strings .Contains (escapedInnerText , "&#48;\t \t " ) {
325+ t .Fatal ("Inner Text should keep plain text" )
326+ }
327+
328+ }
329+
283330func TestOutputXMLWithNamespacePrefix (t * testing.T ) {
284331 s := `<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body></S:Body></S:Envelope>`
285332 doc , _ := Parse (strings .NewReader (s ))
0 commit comments