Unbreak short circuit for arrays

This problem have been making filters potentially fail silently since
2009. Also add tests for arrays to make sure that no problems arise
when short circuit is used.

Bug: T204841
Change-Id: Ie4e2e06498c1202ba73afcc5d164a72427abbca5
This commit is contained in:
Daimona Eaytoy 2018-09-21 13:32:42 +02:00
parent 237f5170c1
commit d9d5af3890
4 changed files with 22 additions and 1 deletions

View file

@ -738,6 +738,16 @@ class AbuseFilterParser {
switch ( $this->mCur->type ) {
case AFPToken::TID:
if ( $this->mShortCircuit ) {
$prev = $this->getState();
$this->move();
if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === '[' ) {
// If the variable represented by $tok is an array, don't break already: $result
// would be null and null[idx] will throw. Instead, skip the whole element (T204841)
$idx = new AFPData();
$this->doLevelSemicolon( $idx );
} else {
$this->setState( $prev );
}
break;
}
$var = strtolower( $tok );

View file

@ -10,6 +10,9 @@ i := [['1', 2], '3'];
j := [1];
k := ['1'];
l := [];
m := 42;
n := [0,1];
a == b & a === b & a != c & b != d & a == e & a !== e & f == g & f !== g & h == i & h !== i & e != i & j != 1 &
k != '1' & l == false & l == null & l !== false & l !== null & false == l & null == l & false !== l & null !== l
k != '1' & l == false & l == null & l !== false & l !== null & false == l & null == l & false !== l & null !== l &
b[5**2/((4+1)*5)] == a[43-m] & a[n[0]] === b[n[m-42]]

View file

@ -0,0 +1 @@
NOT MATCH

View file

@ -0,0 +1,7 @@
/* See T204841 */
a := [false, false];
b := [false, false];
c := 42;
d := [0,1];
a[0] != false & b[1] != false & (b[5**2/(5*(4+1))] !== a[43-c] | a[d[0]] === b[d[c-41]])