Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: catastrophic backtracking in astUtils linebreak regex (fixes #7893…
…) (#7898) * Fix: catastrophic backtracking in astUtils linebreak regex (fixes #7893) This fixes an issue where `astUtils.getLocationFromRangeIndex` and `astUtils.getRangeIndexFromLocation` were using a regular expression susceptible to catastrophic backtracking. The match would take quadratic time in the length of the last line of the file. Since the file in #7893 contains a 1.5 million character source map URL on the last line, rules like `no-multiple-empty-lines` would hang when using ast-utils to split the file into lines. This issue only applies to files without trailing newlines, and is only noticable when the last line of the file contains more than 30000 characters or so. Since only a few rules use these `astUtils` functions, this would only appear when either `no-useless-escape` or `no-multiple-empty-lines` reports an error for the file. Simplified example: Node 7.4.0 hangs when evaluating this expression. ```js /[^\n]*\n/.test('A'.repeat(1000000)) ``` * Add explanatory comments
- Loading branch information