]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Fix handling of empty array index
authorJoshua Spence <josh@freelancer.com>
Tue, 8 Dec 2015 21:09:02 +0000 (08:09 +1100)
committerJoshua Spence <josh@freelancer.com>
Tue, 8 Dec 2015 21:09:02 +0000 (08:09 +1100)
Fix handling of empty array index by `ArcanistCurlyBraceArrayIndexXHPASTLinterRule`.

Auditors: epriestley

src/lint/linter/xhpast/rules/ArcanistCurlyBraceArrayIndexXHPASTLinterRule.php
src/lint/linter/xhpast/rules/__tests__/curly-brace-array-index/array_push.lint-test [new file with mode: 0644]

index 2d2fa171b9022726596a47557dac1d6458b97609..99b3ab944a862b82354220592c9c0d8daecfae57 100644 (file)
@@ -19,6 +19,10 @@ final class ArcanistCurlyBraceArrayIndexXHPASTLinterRule
     foreach ($index_accesses as $index_access) {
       $tokens = $index_access->getChildByIndex(1)->getTokens();
 
+      if (!$tokens) {
+        continue;
+      }
+
       $left_brace = head($tokens)->getPrevToken();
       while (!$left_brace->isSemantic()) {
         $left_brace = $left_brace->getPrevToken();
diff --git a/src/lint/linter/xhpast/rules/__tests__/curly-brace-array-index/array_push.lint-test b/src/lint/linter/xhpast/rules/__tests__/curly-brace-array-index/array_push.lint-test
new file mode 100644 (file)
index 0000000..266b284
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+$x[] = 'value';
+~~~~~~~~~~