Skip to content

Commit a7af617

Browse files
CopilotFDiskas
andcommitted
Remove unnecessary escaping of /* sequences in JSDoc comments
Co-authored-by: FDiskas <[email protected]>
1 parent 91dee67 commit a7af617

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

src/schema-parser/schema-formatters.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,16 @@ export class SchemaFormatters {
105105
escapeJSDocContent = (content) => {
106106
if (!content) return "";
107107
// Escape */ sequences to prevent breaking out of JSDoc comments
108-
// Escape /* sequences to prevent creating nested comments
108+
// Note: /* sequences inside JSDoc comments are harmless and don't need escaping
109109
return content
110-
.replace(/\*\//g, "*\\/")
111-
.replace(/\/\*/g, "\\/*");
110+
.replace(/\*\//g, "*\\/");
112111
};
113112

114113
formatDescription = (description, inline) => {
115114
if (!description) return "";
116115

117116
// Check if content is already escaped - if so, don't escape again
118-
const isAlreadyEscaped = description.includes('*\\/') || description.includes('\\/*');
117+
const isAlreadyEscaped = description.includes('*\\/');
119118

120119
// Escape JSDoc comment characters only if not already escaped
121120
const escapedDescription = isAlreadyEscaped ? description : this.escapeJSDocContent(description);

templates/base/route-docs.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const jsDocDescription = raw.description ?
99
const jsDocLines = _.compact([
1010
_.size(raw.tags) && ` * @tags ${raw.tags.join(", ")}`,
1111
` * @name ${pascalCase(routeName.usage)}`,
12-
raw.summary && ` * @summary ${escapeJSDocContent(raw.summary)}`,
12+
raw.summary && ` * @summary ${formatDescription(raw.summary, true)}`,
1313
` * @request ${_.upperCase(request.method)}:${raw.route}`,
1414
raw.deprecated && ` * @deprecated`,
1515
routeName.duplicate && ` * @originalName ${routeName.original}`,
@@ -18,7 +18,7 @@ const jsDocLines = _.compact([
1818
...(config.generateResponses && raw.responsesTypes.length
1919
? raw.responsesTypes.map(
2020
({ type, status, description, isSuccess }) =>
21-
` * @response \`${status}\` \`${_.replace(_.replace(type, /\/\*/g, "\\*"), /\*\//g, "*\\")}\` ${escapeJSDocContent(description)}`,
21+
` * @response \`${status}\` \`${_.replace(_.replace(type, /\/\*/g, "\\*"), /\*\//g, "*\\")}\` ${formatDescription(description, true)}`,
2222
)
2323
: []),
2424
]).map(str => str.trimEnd()).join("\n");

tests/__snapshots__/extended.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27686,7 +27686,7 @@ export interface SecretScanningUpdateAlertPayload {
2768627686
export interface SelectedActions {
2768727687
/** Whether GitHub-owned actions are allowed. For example, this includes the actions in the \`actions\` organization. */
2768827688
github_owned_allowed: boolean;
27689-
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa\\/*\`." */
27689+
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa/*\`." */
2769027690
patterns_allowed: string[];
2769127691
/** Whether actions in GitHub Marketplace from verified creators are allowed. Set to \`true\` to allow all GitHub Marketplace actions by verified creators. */
2769227692
verified_allowed: boolean;

tests/__snapshots__/simple.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15493,7 +15493,7 @@ export enum SecretScanningAlertState {
1549315493
export interface SelectedActions {
1549415494
/** Whether GitHub-owned actions are allowed. For example, this includes the actions in the \`actions\` organization. */
1549515495
github_owned_allowed: boolean;
15496-
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa\\/*\`." */
15496+
/** Specifies a list of string-matching patterns to allow specific action(s). Wildcards, tags, and SHAs are allowed. For example, \`monalisa/octocat@*\`, \`monalisa/octocat@v2\`, \`monalisa/*\`." */
1549715497
patterns_allowed: string[];
1549815498
/** Whether actions in GitHub Marketplace from verified creators are allowed. Set to \`true\` to allow all GitHub Marketplace actions by verified creators. */
1549915499
verified_allowed: boolean;

tests/spec/jsdoc-escaping/__snapshots__/basic.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ exports[`jsdoc-escaping > should escape JSDoc comment characters in descriptions
1313
* ---------------------------------------------------------------
1414
*/
1515
16-
/** Information schema with malicious **\\/ window.location='http://evil.com' \\/** content */
16+
/** Information schema with malicious **\\/ window.location='http://evil.com' /** content */
1717
export interface Information {
18-
/** The ID of the information record. Contains **\\/ dangerous content \\/** here. */
18+
/** The ID of the information record. Contains **\\/ dangerous content /** here. */
1919
id?: number;
20-
/** Title field with *\\/ and \\/* characters that could break comments */
20+
/** Title field with *\\/ and /* characters that could break comments */
2121
title?: string;
2222
/**
2323
* Multi-line description
2424
* with *\\/ characters
25-
* and \\/* other markers
25+
* and /* other markers
2626
* that could break JSDoc comments
2727
*/
2828
content?: string;
@@ -291,7 +291,7 @@ export class Api<
291291
* @description Get service point file of all Nordic countries (SE,FI,DK,NO) from S3 storage. You can download previous service point file upto 7 days from current date. This is equivalent to **\\/information** endpoint with parameters \`countryCode:SE,FI,DK,NO\` and \`context:ALL\` and header \`Accept-Encoding:gzip\`.
292292
*
293293
* @name InformationList
294-
* @summary Get service point file with **\\/ alert('XSS') \\/** injection attempt
294+
* @summary Get service point file with **\\/ alert('XSS') /** injection attempt
295295
* @request GET:/information
296296
*/
297297
informationList: (params: RequestParams = {}) =>

tests/spec/jsdoc-escaping/basic.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ describe("jsdoc-escaping", async () => {
3232
expect(content).not.toMatch(/\*\/ window\./); // No unescaped window manipulation
3333
expect(content).not.toMatch(/\*\/ dangerous content \*\//); // No unescaped dangerous content
3434

35-
// Check that escaping is applied - look for backslash escapes
35+
// Check that only necessary escaping is applied
3636
expect(content).toMatch(/\*\\\//); // Should contain escaped */
37-
expect(content).toMatch(/\\\//); // Should contain escaped /*
37+
expect(content).not.toMatch(/\\\*\//); // Should NOT contain escaped /* sequences
3838

3939
// Check that alert and window are escaped
4040
expect(content).toMatch(/alert\('XSS'\)/); // Should still contain the content but safely escaped

0 commit comments

Comments
 (0)