@@ -2695,6 +2695,41 @@ int main( int argc, const char ** argv )
2695
2695
XMLTest (" Test attribute encode with a Hex value" , value5, " !" ); // hex value in unicode value
2696
2696
}
2697
2697
2698
+ // ---------- XMLPrinter Apos Escaping ------
2699
+ {
2700
+ const char * testText = " text containing a ' character" ;
2701
+ XMLDocument doc;
2702
+ XMLElement* element = doc.NewElement ( " element" );
2703
+ doc.InsertEndChild ( element );
2704
+ element->SetAttribute ( " attrib" , testText );
2705
+ {
2706
+ XMLPrinter defaultPrinter;
2707
+ doc.Print ( &defaultPrinter );
2708
+ const char * defaultOutput = defaultPrinter.CStr ();
2709
+ const bool foundTextWithUnescapedApos = (strstr (defaultOutput, testText) != nullptr );
2710
+ XMLTest (" Default XMLPrinter should escape ' characters" , false , foundTextWithUnescapedApos);
2711
+ {
2712
+ XMLDocument parsingDoc;
2713
+ parsingDoc.Parse (defaultOutput);
2714
+ const XMLAttribute* attrib = parsingDoc.FirstChildElement (" element" )->FindAttribute (" attrib" );
2715
+ XMLTest (" Default XMLPrinter should output parsable xml" , testText, attrib->Value (), true );
2716
+ }
2717
+ }
2718
+ {
2719
+ XMLPrinter customPrinter (0 , false , 0 , XMLPrinter::DONT_ESCAPE_APOS_CHARS_IN_ATTRIBUTES);
2720
+ doc.Print ( &customPrinter );
2721
+ const char * customOutput = customPrinter.CStr ();
2722
+ const bool foundTextWithUnescapedApos = (strstr (customOutput, testText) != nullptr );
2723
+ XMLTest (" Custom XMLPrinter should not escape ' characters" , true , foundTextWithUnescapedApos);
2724
+ {
2725
+ XMLDocument parsingDoc;
2726
+ parsingDoc.Parse (customOutput);
2727
+ const XMLAttribute* attrib = parsingDoc.FirstChildElement (" element" )->FindAttribute (" attrib" );
2728
+ XMLTest (" Custom XMLPrinter should output parsable xml" , testText, attrib->Value (), true );
2729
+ }
2730
+ }
2731
+ }
2732
+
2698
2733
// ----------- Performance tracking --------------
2699
2734
{
2700
2735
#if defined( _MSC_VER )
0 commit comments