<commit_before>package groovy.bugs

import java.io.StringWriter
import groovy.xml.MarkupBuilder

/** 
 * Tests that special XML chars are entitized by MarkupBuilder.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
class Groovy593_Bug extends GroovyTestCase {
    
    StringWriter writer = new StringWriter()
    MarkupBuilder chars = new MarkupBuilder(writer)
    XmlParser parser = new XmlParser()
    String expectedXML = <<<EOF
<chars>
  <ampersand a='&amp;'>&amp;</ampersand>
  <quote>&quot;</quote>
  <lessthan attr='value'>chars: &amp; &lt; &gt; &quot;</lessthan>
  <element attr='value 1 &amp; 2'>chars: &amp; &lt; &gt; &quot; in middle</element>
  <greaterthan>&gt;</greaterthan>
</chars>
EOF

    void testBug() {
        // XML characters to test with
        chars.chars {
            ampersand(a: "&", "&")
            quote("\'")
            lessthan(attr: "value", "chars: & < > \'") 
            element(attr: "value 1 & 2", "chars: & < > \' in middle")
            greaterthan(">")
        }
        //DEBUG
        //println writer

        // Test MarkupBuilder state with expectedXML
        assertEquals(expectedXML, writer.toString())

        // parser will throw a SAXParseException if XML is not valid
        parser.parseText(writer.toString())
    }
}
<commit_msg>Fix the crlf handling, depending on operating system.<commit_after>package groovy.bugs

import java.io.StringWriter
import groovy.xml.MarkupBuilder

/** 
 * Tests that special XML chars are entitized by MarkupBuilder.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 * @version Revision 1.2 $
 *
 *     Fix the crlf handling, depending on operating system.
 *
 *     @author <a href="mailto:<EMAIL>"><NAME></a>
 */
class Groovy593_Bug extends GroovyTestCase {
    
    StringWriter writer = new StringWriter()
    MarkupBuilder chars = new MarkupBuilder(writer)
    XmlParser parser = new XmlParser()
    String expectedXML = <<<EOF
<chars>
  <ampersand a='&amp;'>&amp;</ampersand>
  <quote>&quot;</quote>
  <lessthan attr='value'>chars: &amp; &lt; &gt; &quot;</lessthan>
  <element attr='value 1 &amp; 2'>chars: &amp; &lt; &gt; &quot; in middle</element>
  <greaterthan>&gt;</greaterthan>
</chars>
EOF

    void testBug() {
        // XML characters to test with
        chars.chars {
            ampersand(a: "&", "&")
            quote("\'")
            lessthan(attr: "value", "chars: & < > \'") 
            element(attr: "value 1 & 2", "chars: & < > \' in middle")
            greaterthan(">")
        }
        //DEBUG
        //println writer

        // Test MarkupBuilder state with expectedXML
	// Handling the cr lf characters, depending on operating system. 
        outputValue = writer.toString()
        if (expectedXML.indexOf("\r\n") >= 0 && outputValue.indexOf("\r\n") < 0) {
                assert expectedXML.replaceAll("\r\n", "\n").length() == outputValue.length()
                assertEquals(expectedXML.replaceAll("\r\n", "\n"), outputValue)
        }
        else if (expectedXML.indexOf("\r\n") < 0 && outputValue.indexOf("\r\n") >= 0) {
                assert expectedXML.length() == outputValue.replaceAll("\r\n", "\n").length()
                assertEquals(expectedXML, outputValue.replaceAll("\r\n", "\n"))
        }

        // parser will throw a SAXParseException if XML is not valid
        parser.parseText(writer.toString())
    }
}

{'fraction_non_alphanumeric': 0.1556477912837237, 'fraction_numerical': 0.005929439667951379, 'mean_word_length': 2.667391304347826, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4217262', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1019, 'n_words': 261}