mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 13:46:48 +00:00
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:
parent
237f5170c1
commit
d9d5af3890
|
@ -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 );
|
||||
|
|
|
@ -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]]
|
||||
|
|
1
tests/parserTests/array-shortcircuit.r
Normal file
1
tests/parserTests/array-shortcircuit.r
Normal file
|
@ -0,0 +1 @@
|
|||
NOT MATCH
|
7
tests/parserTests/array-shortcircuit.t
Normal file
7
tests/parserTests/array-shortcircuit.t
Normal 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]])
|
Loading…
Reference in a new issue