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

Looping when we use the wildcard regex like (.*) #40

Open
rahulnatarajan98 opened this issue Sep 24, 2020 · 4 comments
Open

Looping when we use the wildcard regex like (.*) #40

rahulnatarajan98 opened this issue Sep 24, 2020 · 4 comments

Comments

@rahulnatarajan98
Copy link

The Ranges for regular expression makes an infinite loop while trying to use wildcard regex (.*)

@ElonSchliessMuskel
Copy link

Same issue here and still not fixed. Unfortunately the script is not usable in this state, because the whole tab crashes, even if the highlight function is called within a try/catch block.

@rahulnatarajan98 have you already found a solution or do you know exactly what is causing the error? Then maybe we could check if the regex fulfills this crash condition and then not call the highlight function afterwards.

@rahulnatarajan98
Copy link
Author

Yeah. I created a if statement stating the regex exactly matches with ".*" then ranges array should have the index starting from 0 to length of the matching string.

Also, we should run the while loop whenever the regex value is not equal to .*

Doing this is not a quite good idea. But this will overcome the issue.

@ElonSchliessMuskel
Copy link

Okay, I see. Thank you. The problem with this approach is that there are an infinite number of regular expressions that will cause a crash.
A random example: /(?!thiswillcrash)/g
So a blacklist of "bad" patterns is not very useful. For my project I need a general solution. Until the problem is not solved, I have to check somehow in advance if the regex can cause a crash and not call the highlight function afterwards. Such a general way exists: If you insert the expression into regexr.com, a warning will appear saying that this script can cause an infinite number of matches.

Since the tab crashes all the time and the devtools disconnect immediately, it is difficult to investigate the error. So I can only assume that this is the problem. I was hoping that you have already taken a closer look at the problem or found a general solution.

@rahulnatarajan98
Copy link
Author

Actually, I had validation checks before using the regex in the plugin. I used the RegExp Object in Javascript in creating a regex from a string. For example
var regex = new RegExp('(?thiswillcrash)')

In JS, this regex wont get created as it in invalid regular expression.
I also made the plugin to run for valid regular expressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants