Catastrophic backtracking in require-i18n-strings regular expressions
In gitlab-org/gitlab!33692 (merged) the static-analysis
job was timing out.
It turns out the reason is that there's a string added by that MR which causes catastrophic backtracking in require-i18n-strings
.
Here's a small patch which reproduces this in the test suite:
diff --git a/tests/lib/rules/require-i18n-strings.js b/tests/lib/rules/require-i18n-strings.js
index bf7dc57..24c90d3 100644
--- a/tests/lib/rules/require-i18n-strings.js
+++ b/tests/lib/rules/require-i18n-strings.js
@@ -29,6 +29,7 @@ const error = 'Should not have non i18n strings';
var ruleTester = new RuleTester();
ruleTester.run('require-i18n-strings', rule, {
valid: [
+ "const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghipqrstuvwxyz0123456789 '",
"foo = __('Bar')",
"var arr = { name: __('Unassigned') }",
'Dropzone.autoDiscover = false;',
Note I've intentionally not opened an MR on this, since it would cause the CI runner to be maxed out until the job times out (perhaps 90 minutes?) which is unnecessarily wasteful
The fix is to rewrite all regular expressions in require-i18n-strings
vulnerable to this kind of thing, e.g.:
This article has some guidance on how to write regular expressions without this behaviour. The key take-away is:
The solution is simple. When nesting repetition operators, make absolutely sure that there is only one way to match the same match. If repeating the inner loop 4 times and the outer loop 7 times results in the same overall match as repeating the inner loop 6 times and the outer loop 2 times, you can be sure that the regex engine will try all those combinations.