Skip to content

Commit fde271e

Browse files
committed
[Core, Java] Fix Windows issues
Document.createCDATASection seems to convert "\n" to "\r\n" on Windows, in case the data originally contains "\r\n" line separators the result becomes "\r\r\n", which are displayed as double line breaks. With Gherkin v4 the parsed data will always use LF (Unix) line endings, even if the feature file has CRLF (Windows) line endings.
1 parent 2ddc4b3 commit fde271e

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

core/src/main/java/cucumber/runtime/formatter/JUnitFormatter.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ private Element createElementWithMessage(Document doc, StringBuilder sb, String
322322

323323
private Element createElement(Document doc, StringBuilder sb, String elementType) {
324324
Element child = doc.createElement(elementType);
325-
child.appendChild(doc.createCDATASection(sb.toString()));
325+
// the createCDATASection method seems to convert "\n" to "\r\n" on Windows, in case
326+
// data originally contains "\r\n" line separators the result becomes "\r\r\n", which
327+
// are displayed as double line breaks.
328+
child.appendChild(doc.createCDATASection(sb.toString().replace(System.lineSeparator(), "\n")));
326329
return child;
327330
}
328331

core/src/test/java/cucumber/runtime/formatter/JUnitFormatterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void should_format_skipped_scenario() throws Throwable {
119119
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
120120
"<testsuite failures=\"0\" name=\"cucumber.runtime.formatter.JUnitFormatter\" skipped=\"1\" tests=\"1\" time=\"0.003\">\n" +
121121
" <testcase classname=\"feature name\" name=\"scenario name\" time=\"0.003\">\n" +
122-
" <skipped message=\"" + stackTrace.replace("\n\t", "&#10;&#9;") + "\"><![CDATA[" +
122+
" <skipped message=\"" + stackTrace.replace("\n\t", "&#10;&#9;").replaceAll("\r", "&#13;") + "\"><![CDATA[" +
123123
"Given first step............................................................skipped\n" +
124124
"When second step............................................................skipped\n" +
125125
"Then third step.............................................................skipped\n" +

java/src/test/java/cucumber/runtime/java/test/SubstitutionStepdefs.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public void an_Admin_grants_me_role_rights(String role) throws Throwable {
3232

3333
@Then("^I should receive an email with the body:$")
3434
public void I_should_receive_an_email_with_the_body(String body) throws Throwable {
35-
String expected = String.format("Dear %s,%n" +
36-
"You have been granted %s rights. You are %s. Please be responsible.%n" +
35+
String expected = String.format("Dear %s,\n" +
36+
"You have been granted %s rights. You are %s. Please be responsible.\n" +
3737
"-The Admins", name, role, details);
3838
assertEquals(expected, body);
3939
}

0 commit comments

Comments
 (0)