From b0fa58e8617036fd8914036cf226e2a8aaabca9b Mon Sep 17 00:00:00 2001 From: vivganes Date: Tue, 30 Jul 2019 23:17:20 +0530 Subject: [PATCH 1/2] Escape reserved asciidoc character in generated documentation See gh-17663 --- .../SingleConfigurationTableEntry.java | 2 +- .../SingleConfigurationTableEntryTests.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java index 1d9d517a18..3ba620b297 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java @@ -76,7 +76,7 @@ class SingleConfigurationTableEntry extends ConfigurationTableEntry { builder.append("|"); } else { - builder.append("|+++", this.description, "+++"); + builder.append("|+++", this.description.replace("|", "\\|"), "+++"); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java index 291310cdcb..ef84a2459e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java @@ -86,6 +86,20 @@ class SingleConfigurationTableEntryTests { + "|+++This is a description.+++" + NEWLINE); } + @Test + void descriptionWithPipe() { + ConfigurationMetadataProperty property = new ConfigurationMetadataProperty(); + property.setId("spring.test.prop"); + property.setDefaultValue("first\\second"); + property.setDescription("This is a description with a | pipe."); + property.setType("java.lang.String"); + SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property); + AsciidocBuilder builder = new AsciidocBuilder(); + entry.write(builder); + assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+first\\\\second+`" + NEWLINE + + "|+++This is a description with a \\| pipe.+++" + NEWLINE); + } + @Test void mapProperty() { ConfigurationMetadataProperty property = new ConfigurationMetadataProperty(); From f68c7a751f353b8c203c329b5dcd0461915cf867 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 31 Jul 2019 10:17:14 +0200 Subject: [PATCH 2/2] Polish "Escape reserved asciidoc character in generated documentation" See gh-17663 --- .../boot/configurationdocs/SingleConfigurationTableEntry.java | 3 ++- .../configurationdocs/SingleConfigurationTableEntryTests.java | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java index 3ba620b297..f1832a6944 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/main/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntry.java @@ -76,7 +76,8 @@ class SingleConfigurationTableEntry extends ConfigurationTableEntry { builder.append("|"); } else { - builder.append("|+++", this.description.replace("|", "\\|"), "+++"); + String cleanedDescription = this.description.replace("|", "\\|"); + builder.append("|+++", cleanedDescription, "+++"); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java index ef84a2459e..8da4cc76c7 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-docs/src/test/java/org/springframework/boot/configurationdocs/SingleConfigurationTableEntryTests.java @@ -90,13 +90,12 @@ class SingleConfigurationTableEntryTests { void descriptionWithPipe() { ConfigurationMetadataProperty property = new ConfigurationMetadataProperty(); property.setId("spring.test.prop"); - property.setDefaultValue("first\\second"); property.setDescription("This is a description with a | pipe."); property.setType("java.lang.String"); SingleConfigurationTableEntry entry = new SingleConfigurationTableEntry(property); AsciidocBuilder builder = new AsciidocBuilder(); entry.write(builder); - assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|`+first\\\\second+`" + NEWLINE + assertThat(builder.toString()).isEqualTo("|`+spring.test.prop+`" + NEWLINE + "|" + NEWLINE + "|+++This is a description with a \\| pipe.+++" + NEWLINE); }