From 7c74979b7d1efe9d0507d77672e13c556f662964 Mon Sep 17 00:00:00 2001
From: Jaret Cantu <jaret.cantu@timesys.com>
Date: Sat, 8 Feb 2014 23:29:05 -0500
Subject: [PATCH 2/3] DEBIAN: Correct entity encoding.

TinyXML incorrectly encodes text element containing an ampersand followed by either x or #.
Origin: http://sourceforge.net/tracker/index.php?func=detail&aid=3031828&group_id=13559&atid=313559
---
 tinyxml.cpp | 25 +------------------------
 xmltest.cpp | 10 ++++++++++
 2 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/tinyxml.cpp b/tinyxml.cpp
index 9c161df..fccd8dc 100644
--- a/tinyxml.cpp
+++ b/tinyxml.cpp
@@ -57,30 +57,7 @@ void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString )
 	{
 		unsigned char c = (unsigned char) str[i];
 
-		if (    c == '&' 
-		     && i < ( (int)str.length() - 2 )
-			 && str[i+1] == '#'
-			 && str[i+2] == 'x' )
-		{
-			// Hexadecimal character reference.
-			// Pass through unchanged.
-			// &#xA9;	-- copyright symbol, for example.
-			//
-			// The -1 is a bug fix from Rob Laveaux. It keeps
-			// an overflow from happening if there is no ';'.
-			// There are actually 2 ways to exit this loop -
-			// while fails (error case) and break (semicolon found).
-			// However, there is no mechanism (currently) for
-			// this function to return an error.
-			while ( i<(int)str.length()-1 )
-			{
-				outString->append( str.c_str() + i, 1 );
-				++i;
-				if ( str[i] == ';' )
-					break;
-			}
-		}
-		else if ( c == '&' )
+		if ( c == '&' )
 		{
 			outString->append( entity[0].str, entity[0].strLength );
 			++i;
diff --git a/xmltest.cpp b/xmltest.cpp
index 663c157..b38587f 100644
--- a/xmltest.cpp
+++ b/xmltest.cpp
@@ -1366,6 +1366,16 @@ int main()
 		}*/
 	}
 
+	#ifdef TIXML_USE_STL
+	{
+		TiXmlDocument xml;
+		xml.Parse("<foo>foo&amp;#xa+bar</foo>");
+		std::string str;
+		str << xml;
+		XmlTest( "Entity escaping", "<foo>foo&amp;#xa+bar</foo>", str.c_str() );
+	}
+	#endif
+
 	/*  1417717 experiment
 	{
 		TiXmlDocument xml;
-- 
2.0.0

