File tree Expand file tree Collapse file tree 3 files changed +14
-13
lines changed
tests/spec/jsdoc-escaping Expand file tree Collapse file tree 3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -106,19 +106,20 @@ export class SchemaFormatters {
106106 if ( ! content ) return "" ;
107107 // Escape */ sequences to prevent breaking out of JSDoc comments
108108 // Note: /* sequences inside JSDoc comments are harmless and don't need escaping
109- return content
110- . replace ( / \* \/ / g, "*\\/" ) ;
109+ return content . replace ( / \* \/ / g, "*\\/" ) ;
111110 } ;
112111
113112 formatDescription = ( description , inline ) => {
114113 if ( ! description ) return "" ;
115114
116115 // Check if content is already escaped - if so, don't escape again
117- const isAlreadyEscaped = description . includes ( ' *\\/' ) ;
118-
116+ const isAlreadyEscaped = description . includes ( " *\\/" ) ;
117+
119118 // Escape JSDoc comment characters only if not already escaped
120- const escapedDescription = isAlreadyEscaped ? description : this . escapeJSDocContent ( description ) ;
121-
119+ const escapedDescription = isAlreadyEscaped
120+ ? description
121+ : this . escapeJSDocContent ( description ) ;
122+
122123 const hasMultipleLines = escapedDescription . includes ( "\n" ) ;
123124
124125 if ( ! hasMultipleLines ) return escapedDescription ;
Original file line number Diff line number Diff line change @@ -31,15 +31,15 @@ describe("jsdoc-escaping", async () => {
3131 expect ( content ) . not . toMatch ( / \* \/ a l e r t \( / ) ; // No unescaped code injection
3232 expect ( content ) . not . toMatch ( / \* \/ w i n d o w \. / ) ; // No unescaped window manipulation
3333 expect ( content ) . not . toMatch ( / \* \/ d a n g e r o u s c o n t e n t \* \/ / ) ; // No unescaped dangerous content
34-
34+
3535 // Check that only necessary escaping is applied
36- expect ( content ) . toMatch ( / \* \\ \/ / ) ; // Should contain escaped */
36+ expect ( content ) . toMatch ( / \* \\ \/ / ) ; // Should contain escaped */
3737 expect ( content ) . not . toMatch ( / \\ \* \/ / ) ; // Should NOT contain escaped /* sequences
38-
38+
3939 // Check that alert and window are escaped
4040 expect ( content ) . toMatch ( / a l e r t \( ' X S S ' \) / ) ; // Should still contain the content but safely escaped
4141 expect ( content ) . toMatch ( / w i n d o w \. l o c a t i o n / ) ; // Should still contain but safely escaped
42-
42+
4343 expect ( content ) . toMatchSnapshot ( ) ;
4444 } ) ;
45- } ) ;
45+ } ) ;
Original file line number Diff line number Diff line change 3636 "description" : " The ID of the information record. Contains **/ dangerous content /** here."
3737 },
3838 "title" : {
39- "type" : " string" ,
39+ "type" : " string" ,
4040 "description" : " Title field with */ and /* characters that could break comments"
4141 },
4242 "content" : {
4747 }
4848 }
4949 }
50- }
50+ }
You can’t perform that action at this time.
0 commit comments