From 26911904df5a46e19c593481d02863345789680c Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Thu, 4 Jul 2024 09:50:24 +0200 Subject: [PATCH] Escape ] in rewritten xrefs for downstream doc Supersedes #41651 --- .../generation/AssembleDownstreamDocumentation.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/src/main/java/io/quarkus/docs/generation/AssembleDownstreamDocumentation.java b/docs/src/main/java/io/quarkus/docs/generation/AssembleDownstreamDocumentation.java index 6f23fd809cd4c..2a88d1d2b106c 100755 --- a/docs/src/main/java/io/quarkus/docs/generation/AssembleDownstreamDocumentation.java +++ b/docs/src/main/java/io/quarkus/docs/generation/AssembleDownstreamDocumentation.java @@ -426,7 +426,7 @@ private static String rewriteContent(String fileName, addError(errors, fileName, "Unable to find title for: " + mr.group() + " [" + reference + "]"); title = "~~ unknown title ~~"; } - return "xref:" + trimReference(mr.group(1)) + "[" + title.trim() + "]"; + return "xref:" + trimReference(mr.group(1)) + "[" + escapeXrefTitleForReplaceAll(title) + "]"; }); content = ANGLE_BRACKETS_WITHOUT_DESCRIPTION_PATTERN.matcher(content).replaceAll(mr -> { @@ -436,11 +436,11 @@ private static String rewriteContent(String fileName, addError(errors, fileName, "Unable to find title for: " + mr.group() + " [" + reference + "]"); title = "~~ unknown title ~~"; } - return "xref:" + trimReference(mr.group(1)) + "[" + title.trim() + "]"; + return "xref:" + trimReference(mr.group(1)) + "[" + escapeXrefTitleForReplaceAll(title) + "]"; }); content = ANGLE_BRACKETS_WITH_DESCRIPTION_PATTERN.matcher(content).replaceAll(mr -> { - return "xref:" + trimReference(mr.group(1)) + "[" + mr.group(2).trim() + "]"; + return "xref:" + trimReference(mr.group(1)) + "[" + escapeXrefTitleForReplaceAll(mr.group(2)) + "]"; }); content = XREF_GUIDE_PATTERN.matcher(content).replaceAll(mr -> { @@ -466,6 +466,10 @@ private static String rewriteContent(String fileName, return content; } + private static String escapeXrefTitleForReplaceAll(String title) { + return title.trim().replace("]", "\\\\]"); + } + private static String trimReference(String reference) { reference = normalizeAdoc(reference);