Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(javascript) some content trigger regexp catastrophic backtracking #2664

Closed
jiaoyin opened this issue Aug 23, 2020 · 2 comments
Closed

(javascript) some content trigger regexp catastrophic backtracking #2664

jiaoyin opened this issue Aug 23, 2020 · 2 comments
Labels
bug help welcome Could use help from community language

Comments

@jiaoyin
Copy link

jiaoyin commented Aug 23, 2020

Describe the issue
Using highlightBlock API in the web editor, some content similar to the following will make the browser unresponsive. After analysis, such content may trigger a disastrous regular expression backtracking

Which language seems to have the issue?

javascript

Are you using highlight or highlightAuto?
use highlightBlock actually uses highlightAuto

Sample Code to Reproduce

 
///////////////////////////////////////// 长连接按照 ServiceID 分开用不同的类处理 ///////////////////////////////////////////

@protocol HTSWebSockectServiceHandler 

- (void)handleWithPushMessage:(PushMessageBaseObject * _Nonnull)frame;

@end

/// 
@interface HTSWebSockectServiceCommonHandler : NSObject
<
HTSWebSockectServiceHandler
>

@end

///
@interface HTSWebSockectServiceGeckoHandler : NSObject 
<
HTSWebSockectServiceHandler
>

@end

/// Add More...

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 hljs.highlightBlock(document.querySelector('#test'));

**Expected behavior**

Although the code is not actually javascript, I hope to highlight the corresponding keywords correctly, at least not to block the browser.

**Additional context**
version 10.1.2
javascript language actually use regexp is  `const  reg = /(^#![ ]*\/.*\bnode\b.*)|(^\s*['"]use (strict|asm)['"])|(')|(")|(html`)|(css`)|(`)|(\/\/)|(\/\*\*)|(\/\*)|(\b(0[bB][01]+)n?)|(\b(0[oO][0-7]+)n?)|((-?)(\b0[xX][a-fA-F0-9]+|(\b\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?)n?)|([{,\n]\s*(?=(((\/\/.*)|(\/\*(.|\n)*\*\/))\s*)*[A-Za-z$_][0-9A-Za-z$_]*\s*:))|((!|!=|!==|%|%=|&|&&|&=|\*|\*=|\+|\+=|,|-|-=|\/=|\/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\?|\[|\{|\(|\^|\^=|\||\|=|\|\||~|\b(case|return|throw)\b)\s*)|(\b(function)(?=\b|\s))|(\$[(.])|(\.\s*[a-zA-Z_]\w*)|(\b(class)(?=\b|\s))|(\b(constructor)(?=\b|\s))|((get|set)\s+(?=[A-Za-z$_][0-9A-Za-z$_]*\())|(#(?!!))/gm`
reg.exec above content can reproduce
@jiaoyin jiaoyin added bug help welcome Could use help from community language labels Aug 23, 2020
@egor-rogov
Copy link
Collaborator

Looks like the same as #2656. Has been fixed recently in #2657.

@joshgoebel
Copy link
Member

Will try to push a new release this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help welcome Could use help from community language
Projects
None yet
Development

No branches or pull requests

3 participants