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

Supplying empty regex crashes browser #754

Closed
JulianVGit opened this issue Jul 2, 2024 · 2 comments
Closed

Supplying empty regex crashes browser #754

JulianVGit opened this issue Jul 2, 2024 · 2 comments
Labels

Comments

@JulianVGit
Copy link

JulianVGit commented Jul 2, 2024

When supplying and empty regex as a custom param for syntax, the browser crashes:

format('SELECT * FROM whatever', {
  language: 'sql',
  paramTypes: {
      custom: [{regex: ''}]
  },
}
@JulianVGit JulianVGit added the bug label Jul 2, 2024
@JulianVGit JulianVGit changed the title Suppling Supplying empty regex crashes browser Jul 2, 2024
@nene
Copy link
Collaborator

nene commented Jul 3, 2024

More correctly, the code will enter an infinite loop, because you have defined a parameter to be an empty string, and there are infinitely many empty strings in any string. So the formatter will correctly detect infinite amount of these custom parameters.

The formatter could possibly check whether the supplied regex is an empty string, and throw a more friendly error message instead of getting stuck in infinite loop. If you're really interested in getting a better error in this specific case, I'm open to a pull request.

However there are infinitely many regexes that would end up matching empty string (for example (|)) and therefore triggering an infinite loop. It's not really feasible to properly validate them all.

@nene
Copy link
Collaborator

nene commented Jul 3, 2024

Oh well. As I'm already looking into this code, might as well add this little extra check.

@nene nene closed this as completed in 34baa64 Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants