Skip to content

Commit

Permalink
Fix XMLTest on Windows
Browse files Browse the repository at this point in the history
XMLTest.testIndentComplicatedJsonObjectWithArrayAndWithConfig fails
when run on Windows due to mismatching linebreaks (that aren't
important for the test's functionality) between the actual and
expected strings.

For the actual strings, linebreaks are canonized to the platform's
native linebreak using `replaceAll("\\n|\\r\\n",
System.getProperty("line.separator")`. However, the expected result is
read from a file, and is left with the linebreaks that were originally
used to create it.

The solution is to perform the same canonization on both strings.

Closes stleary#781
  • Loading branch information
mureinik committed Oct 5, 2023
1 parent 79af389 commit fe45fa9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/test/java/org/json/junit/XMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,8 @@ public void testIndentComplicatedJsonObjectWithArrayAndWithConfig(){
for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
expected.append(buffer, 0, numRead);
}
assertEquals(expected.toString(), actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator")));
assertEquals(expected.toString().replaceAll("\\n|\\r\\n", System.getProperty("line.separator")),
actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator")));
} finally {
if (xmlStream != null) {
xmlStream.close();
Expand Down

0 comments on commit fe45fa9

Please sign in to comment.