@@ -298,6 +298,7 @@ void _JsExtractLiteral(JsDoc* doc, Node* node) {
298298 const char * buf = doc -> buffer ;
299299 size_t offset = doc -> offset ;
300300 char delimiter = buf [offset ];
301+ bool in_char_class = 0 ;
301302 /* skip start of literal */
302303 offset ++ ;
303304 /* search for end of literal */
@@ -306,12 +307,24 @@ void _JsExtractLiteral(JsDoc* doc, Node* node) {
306307 /* escaped character; skip */
307308 offset ++ ;
308309 }
309- else if (buf [offset ] == delimiter ) {
310- const char * start = buf + doc -> offset ;
311- size_t length = offset - doc -> offset + 1 ;
312- JsSetNodeContents (node , start , length );
313- node -> type = NODE_LITERAL ;
314- return ;
310+ else {
311+ /* if in a regex, track if we're in a character class */
312+ if (delimiter == '/' ) {
313+ if ((buf [offset ] == '[' ) && !in_char_class ) {
314+ in_char_class = 1 ;
315+ }
316+ if ((buf [offset ] == ']' ) && in_char_class ) {
317+ in_char_class = 0 ;
318+ }
319+ }
320+ /* if we have found the end of the literal, store it */
321+ if ((buf [offset ] == delimiter ) && !in_char_class ) {
322+ const char * start = buf + doc -> offset ;
323+ size_t length = offset - doc -> offset + 1 ;
324+ JsSetNodeContents (node , start , length );
325+ node -> type = NODE_LITERAL ;
326+ return ;
327+ }
315328 }
316329 /* move onto next character */
317330 offset ++ ;
0 commit comments