Skip to content

Commit 7992efa

Browse files
authored
[Bug] Refactor selective sanitization of > and < symbols in generated markdown descriptions (#377)
* Make case sensitive and ignore < if before placeholder variable * Add regex for code fence and tweak greaterThan * Refactor to escape great than and leave code fence as is * Add compute example * Remove compute docs * Remove compute spec files
1 parent 6e4fd13 commit 7992efa

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

packages/docusaurus-plugin-openapi-docs/src/markdown/createDescription.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
* LICENSE file in the root directory of this source tree.
66
* ========================================================================== */
77

8-
import { greaterThan, lessThan } from "./utils";
8+
import { greaterThan, codeFence } from "./utils";
99

1010
export function createDescription(description: string | undefined) {
1111
if (!description) {
1212
return "";
1313
}
1414
return `\n\n${description
15-
.replace(lessThan, "&lt;")
16-
.replace(greaterThan, "&gt;")}\n\n`;
15+
.replace(greaterThan, "\\>")
16+
.replace(codeFence, function (match) {
17+
return match.replace(/\\>/g, ">");
18+
})}\n\n`;
1719
}

packages/docusaurus-plugin-openapi-docs/src/markdown/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function render(children: Children): string {
4343

4444
// Regex to selectively URL-encode '>' and '<' chars
4545
export const lessThan =
46-
/<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/giu;
46+
/<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/gu;
4747
export const greaterThan =
48-
/(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>?!=/giu;
48+
/(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/gu;
49+
export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;

0 commit comments

Comments
 (0)