Skip to content

Commit 98b5a7c

Browse files
authored
Fix problem with PrettyFormatter printing URL encoded strings
1 parent 606fa07 commit 98b5a7c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ private void printText(WriteEvent event) {
186186
try (BufferedReader lines = new BufferedReader(new StringReader(event.getText()))) {
187187
String line;
188188
while ((line = lines.readLine()) != null) {
189-
builder.append(String.format(STEP_SCENARIO_INDENT + line + "%n"));
189+
builder.append(STEP_SCENARIO_INDENT)
190+
.append(line)
191+
.append(System.lineSeparator()); // Add system line separator - \n won't do it!
190192
}
191193
} catch (IOException e) {
192194
throw new CucumberException(e);

core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,34 @@ void should_handle_scenario_outline() {
165165
" Then third step # path/step_definitions.java:11\n"));
166166
}
167167

168+
@Test
169+
void should_print_encoded_characters() {
170+
171+
Feature feature = TestFeatureParser.parse("path/test.feature", "" +
172+
"Feature: Test feature\n" +
173+
" Scenario: Test Characters\n" +
174+
" Given first step\n" +
175+
" | URLEncoded | %71s%22i%22%3A%7B%22D |\n");
176+
177+
ByteArrayOutputStream out = new ByteArrayOutputStream();
178+
Runtime.builder()
179+
.withFeatureSupplier(new StubFeatureSupplier(feature))
180+
.withAdditionalPlugins(new PrettyFormatter(out))
181+
.withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build())
182+
.withBackendSupplier(new StubBackendSupplier(
183+
new StubStepDefinition("first step", "path/step_definitions.java:7", DataTable.class)))
184+
.build()
185+
.run();
186+
187+
assertThat(out, isBytesEqualTo("" +
188+
189+
"\n" +
190+
"Scenario: Test Characters # path/test.feature:2\n" +
191+
" Given first step # path/step_definitions.java:7\n" +
192+
" | URLEncoded | %71s%22i%22%3A%7B%22D |\n"));
193+
}
194+
195+
168196
@Test
169197
void should_print_tags() {
170198
Feature feature = TestFeatureParser.parse("path/test.feature", "" +

0 commit comments

Comments
 (0)