Skip to content

Commit

Permalink
Fix problem with PrettyFormatter printing URL encoded strings
Browse files Browse the repository at this point in the history
  • Loading branch information
skloessel authored May 2, 2022
1 parent 606fa07 commit 98b5a7c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ private void printText(WriteEvent event) {
try (BufferedReader lines = new BufferedReader(new StringReader(event.getText()))) {
String line;
while ((line = lines.readLine()) != null) {
builder.append(String.format(STEP_SCENARIO_INDENT + line + "%n"));
builder.append(STEP_SCENARIO_INDENT)
.append(line)
.append(System.lineSeparator()); // Add system line separator - \n won't do it!
}
} catch (IOException e) {
throw new CucumberException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,34 @@ void should_handle_scenario_outline() {
" Then third step # path/step_definitions.java:11\n"));
}

@Test
void should_print_encoded_characters() {

Feature feature = TestFeatureParser.parse("path/test.feature", "" +
"Feature: Test feature\n" +
" Scenario: Test Characters\n" +
" Given first step\n" +
" | URLEncoded | %71s%22i%22%3A%7B%22D |\n");

ByteArrayOutputStream out = new ByteArrayOutputStream();
Runtime.builder()
.withFeatureSupplier(new StubFeatureSupplier(feature))
.withAdditionalPlugins(new PrettyFormatter(out))
.withRuntimeOptions(new RuntimeOptionsBuilder().setMonochrome().build())
.withBackendSupplier(new StubBackendSupplier(
new StubStepDefinition("first step", "path/step_definitions.java:7", DataTable.class)))
.build()
.run();

assertThat(out, isBytesEqualTo("" +

"\n" +
"Scenario: Test Characters # path/test.feature:2\n" +
" Given first step # path/step_definitions.java:7\n" +
" | URLEncoded | %71s%22i%22%3A%7B%22D |\n"));
}


@Test
void should_print_tags() {
Feature feature = TestFeatureParser.parse("path/test.feature", "" +
Expand Down

0 comments on commit 98b5a7c

Please sign in to comment.