diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/DocGenerationHelper.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/DocGenerationHelper.java index b8f410ab0b..5a49e176be 100644 --- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/DocGenerationHelper.java +++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/DocGenerationHelper.java @@ -12,6 +12,7 @@ * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2015 ForgeRock AS. + * Portions Copyright 2026 3A Systems, LLC. */ package com.forgerock.opendj.cli; @@ -23,6 +24,7 @@ import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Map; +import java.util.regex.Pattern; /** * This class provides utility functions to help generate reference documentation. @@ -37,6 +39,13 @@ private DocGenerationHelper() { /** FreeMarker template configuration. */ private static Configuration configuration; + /** + * An AsciiDoc attribute reference, such as {@code {name}}, that no backslash escapes. + * Word characters are Unicode ones, as in Asciidoctor. + */ + private static final Pattern ATTRIBUTE_REFERENCE = + Pattern.compile("(? + * + * The generated reference refers to no AsciiDoc attribute: a {@code {name}} in it is the placeholder + * of an option value, written as is in the messages, which AsciiDoc would read as a reference + * to a missing attribute. A reference that is already escaped is left as is, + * so the result of a template can go through another template that includes it. + * + * @param text The generated AsciiDoc text. + * @return The text with each attribute reference escaped by a backslash. + */ + static String escapeAttributeReferences(final String text) { + return ATTRIBUTE_REFERENCE.matcher(text).replaceAll("\\\\$1"); + } + /** * Returns an option synopsis. * diff --git a/opendj-cli/src/test/java/com/forgerock/opendj/cli/DocGenerationHelperTestCase.java b/opendj-cli/src/test/java/com/forgerock/opendj/cli/DocGenerationHelperTestCase.java new file mode 100644 index 0000000000..1ddf1e560d --- /dev/null +++ b/opendj-cli/src/test/java/com/forgerock/opendj/cli/DocGenerationHelperTestCase.java @@ -0,0 +1,107 @@ +/* + * The contents of this file are subject to the terms of the Common Development and + * Distribution License (the License). You may not use this file except in compliance with the + * License. + * + * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the + * specific language governing permission and limitations under the License. + * + * When distributing Covered Software, include this CDDL Header Notice in each file and include + * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL + * Header, with the fields enclosed by brackets [] replaced by your own identifying + * information: "Portions copyright [year] [name of copyright owner]". + * + * Copyright 2026 3A Systems, LLC. + */ +package com.forgerock.opendj.cli; + +import static org.fest.assertions.Assertions.assertThat; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.forgerock.i18n.LocalizableMessage; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Tests that the generated AsciiDoc reference writes the value placeholders of the options + * as text, not as AsciiDoc attribute references. + */ +@SuppressWarnings("javadoc") +public final class DocGenerationHelperTestCase extends CliTestCase { + + private static final String GENDOC = "org.forgerock.opendj.gendoc"; + + /** An AsciiDoc attribute reference that no backslash escapes. */ + private static final Pattern ATTRIBUTE_REFERENCE = Pattern.compile("(?