Skip to content

Commit

Permalink
Escape ] in rewritten xrefs for downstream doc
Browse files Browse the repository at this point in the history
Supersedes #41651
  • Loading branch information
gsmet committed Jul 4, 2024
1 parent 0341c8f commit 2691190
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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 -> {
Expand All @@ -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);

Expand Down

0 comments on commit 2691190

Please sign in to comment.