Skip to content

Commit

Permalink
Merge pull request #41678 from gsmet/fix-downstream-doc-links
Browse files Browse the repository at this point in the history
Escape ] in rewritten xrefs for downstream doc
  • Loading branch information
gsmet authored Jul 4, 2024
2 parents e46f2ec + 2691190 commit 2646b55
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 2646b55

Please sign in to comment.