Fix hang when tokenizing PHP

Fix #75468
This commit is contained in:
Rob Lourens 2019-07-05 12:00:41 -07:00
parent 7e03eb1a1f
commit 32169bcc6e
2 changed files with 28 additions and 4 deletions

View file

@ -23,16 +23,40 @@ function adaptInjectionScope(grammar) {
// Workaround for https://github.com/Microsoft/vscode/issues/40279
// and https://github.com/Microsoft/vscode-textmate/issues/59
function fixBadRegex(grammar) {
function fail(msg) {
throw new Error(`fixBadRegex callback couldn't patch ${msg}. It may be obsolete`);
}
const scopeResolution = grammar.repository['scope-resolution'];
if (scopeResolution) {
const match = scopeResolution.patterns[0].match;
if (match === '(?i)([a-z_\\x{7f}-\\x{7fffffff}\\\\][a-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)') {
scopeResolution.patterns[0].match = '([A-Za-z_\\x{7f}-\\x{7fffffff}\\\\][A-Za-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)';
return;
} else {
fail('scope-resolution.match');
}
} else {
fail('scope-resolution');
}
throw new Error(`fixBadRegex callback couldn't patch the regex. It may be obsolete`);
const functionCall = grammar.repository['function-call'];
if (functionCall) {
const begin0 = functionCall.patterns[0].begin;
if (begin0 === '(?xi)\n(\n \\\\?(?<![a-z0-9_\\x{7f}-\\x{7fffffff}]) # Optional root namespace\n [a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]* # First namespace\n (?:\\\\[a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)+ # Additional namespaces\n)\\s*(\\()') {
functionCall.patterns[0].begin = '(?x)\n(\n \\\\?(?<![a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]) # Optional root namespace\n [a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]* # First namespace\n (?:\\\\[a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]*)+ # Additional namespaces\n)\\s*(\\()';
} else {
fail('function-call.begin0');
}
const begin1 = functionCall.patterns[1].begin;
if (begin1 === '(?i)(\\\\)?(?<![a-z0-9_\\x{7f}-\\x{7fffffff}])([a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)\\s*(\\()') {
functionCall.patterns[1].begin = '(\\\\)?(?<![a-zA-Z0-9_\\x{7f}-\\x{7fffffff}])([a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]*)\\s*(\\()';
} else {
fail('function-call.begin1');
}
} else {
fail('function-call');
}
}
updateGrammar.update('atom/language-php', 'grammars/php.cson', './syntaxes/php.tmLanguage.json', fixBadRegex);

View file

@ -1207,7 +1207,7 @@
"function-call": {
"patterns": [
{
"begin": "(?xi)\n(\n \\\\?(?<![a-z0-9_\\x{7f}-\\x{7fffffff}]) # Optional root namespace\n [a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]* # First namespace\n (?:\\\\[a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)+ # Additional namespaces\n)\\s*(\\()",
"begin": "(?x)\n(\n \\\\?(?<![a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]) # Optional root namespace\n [a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]* # First namespace\n (?:\\\\[a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]*)+ # Additional namespaces\n)\\s*(\\()",
"beginCaptures": {
"1": {
"patterns": [
@ -1238,7 +1238,7 @@
]
},
{
"begin": "(?i)(\\\\)?(?<![a-z0-9_\\x{7f}-\\x{7fffffff}])([a-z_\\x{7f}-\\x{7fffffff}][a-z0-9_\\x{7f}-\\x{7fffffff}]*)\\s*(\\()",
"begin": "(\\\\)?(?<![a-zA-Z0-9_\\x{7f}-\\x{7fffffff}])([a-zA-Z_\\x{7f}-\\x{7fffffff}][a-zA-Z0-9_\\x{7f}-\\x{7fffffff}]*)\\s*(\\()",
"beginCaptures": {
"1": {
"patterns": [