From 98b5a7c4af51916c26b4be742cfe61fcb81248d0 Mon Sep 17 00:00:00 2001 From: skloessel <46377547+skloessel@users.noreply.github.com> Date: Tue, 3 May 2022 00:25:38 +0200 Subject: [PATCH] Fix problem with PrettyFormatter printing URL encoded strings --- .../cucumber/core/plugin/PrettyFormatter.java | 4 ++- .../core/plugin/PrettyFormatterTest.java | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java b/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java index 940e9c84b9..fafdc5daf9 100644 --- a/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java +++ b/core/src/main/java/io/cucumber/core/plugin/PrettyFormatter.java @@ -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); diff --git a/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java b/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java index 8994054b39..3000d436d4 100755 --- a/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java +++ b/core/src/test/java/io/cucumber/core/plugin/PrettyFormatterTest.java @@ -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", "" +