File tree 4 files changed +38
-9
lines changed 4 files changed +38
-9
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ Running the wrapper will generate the local `file://` URL to the generated
55
55
` index.html ` file, e.g.:
56
56
57
57
``` text
58
- file:///path/to/jsdoc/output/jsdoc-cli-wrapper/1.0.3 /index.html
58
+ file:///path/to/jsdoc/output/jsdoc-cli-wrapper/1.0.4 /index.html
59
59
```
60
60
61
61
You can click on or copy this link to open it in your browser. You can also open
@@ -99,10 +99,10 @@ This wrapper resolves both of these minor annoyances.
99
99
``` sh
100
100
$ pnpm jsdoc
101
101
102
- > [email protected] .
3 jsdoc /path/to/jsdoc-cli-wrapper
102
+ > [email protected] .
4 jsdoc /path/to/jsdoc-cli-wrapper
103
103
> node index.js -c jsdoc.json .
104
104
105
- file:///path/to/jsdoc-cli-wrapper/jsdoc/jsdoc-cli-wrapper/1.0.3 /index.html
105
+ file:///path/to/jsdoc-cli-wrapper/jsdoc/jsdoc-cli-wrapper/1.0.4 /index.html
106
106
```
107
107
108
108
Of course, your own project would use ` jsdoc-cli-wrapper ` instead of `node
Original file line number Diff line number Diff line change @@ -183,19 +183,19 @@ export function stripJsonComments(str) {
183
183
for ( let i = 0 ; i !== str . length ; ++ i ) {
184
184
let c = str [ i ]
185
185
186
- if ( c === '\n' ) {
187
- if ( comment === 'line' ) comment = null
188
- } else if ( c . trimStart ( ) === '' ) { // preserve other existing whitespace
189
- } else if ( inString ) {
186
+ if ( inString ) { // check first so illegally escaped whitespace won't hide "
190
187
inString = c !== '"' || escaped
191
188
escaped = c === '\\' && ! escaped
189
+ } else if ( c === '\n' ) {
190
+ if ( comment === 'line' ) comment = null
191
+ } else if ( c . trimStart ( ) === '' ) { // preserve all other existing whitespace
192
192
} else if ( comment ) {
193
193
if ( c === '/' && comment === 'block' && str [ i - 1 ] === '*' ) comment = null
194
194
c = ' '
195
195
} else if ( c === '/' || c === '*' ) { // maybe a comment, don't update comma
196
196
if ( str [ i - 1 ] === '/' ) { // definitely a comment, or else a syntax error
197
197
comment = ( c === '/' ) ? 'line' : 'block'
198
- c = result [ i - 1 ] = ' '
198
+ result [ i - 1 ] = c = ' '
199
199
}
200
200
} else if ( c === ',' ) {
201
201
comma = i
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " jsdoc-cli-wrapper" ,
3
- "version" : " 1.0.3 " ,
3
+ "version" : " 1.0.4 " ,
4
4
"description" : " JSDoc command line interface wrapper" ,
5
5
"main" : " index.js" ,
6
6
"bin" : " ./index.js" ,
Original file line number Diff line number Diff line change @@ -286,5 +286,34 @@ describe('stripJsonComments', () => {
286
286
` JSON at position ${ src . indexOf ( ', // ...but this last comma' ) } `
287
287
)
288
288
} )
289
+
290
+ test ( 'a string contains an escaped space before the closing quote' , ( ) => {
291
+ const src = [
292
+ '{' ,
293
+ ' "opts": {' ,
294
+ ' // This comment should disappear regardless.' ,
295
+ ' "fubar": "If not handled, the comments below will remain.\\ "' ,
296
+ ' /* Escaped space is illegal JSON, but it shouldn\'t hide a' ,
297
+ ' * closing quote and prevent comment removal. */' ,
298
+ ' }' ,
299
+ '}' ] . join ( '\n' )
300
+
301
+ const result = stripJsonComments ( src )
302
+
303
+ expect ( result ) . toBe ( [
304
+ '{' ,
305
+ ' "opts": {' ,
306
+ ' ' ,
307
+ ' "fubar": "If not handled, the comments below will remain.\\ "' ,
308
+ ' ' ,
309
+ ' ' ,
310
+ ' }' ,
311
+ '}' ] . join ( '\n' ) )
312
+ expect ( ( ) => JSON . parse ( result ) ) . toThrowError (
313
+ // It will choke on the space, not the escape slash.
314
+ errPrefix ( ' ' , 'Bad escaped character in' ) +
315
+ ` JSON at position ${ src . indexOf ( '\\ "' ) + 1 } `
316
+ )
317
+ } )
289
318
} )
290
319
} )
You can’t perform that action at this time.
0 commit comments