mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Merge "Allow if without else"
This commit is contained in:
commit
47838715fa
|
@ -23,8 +23,8 @@ class AFPTreeNode {
|
|||
const ARRAY_APPEND = 'ARRAY_APPEND';
|
||||
|
||||
// CONDITIONAL represents both a ternary operator and an if-then-else-end
|
||||
// construct. The format is (condition, evaluated-if-true,
|
||||
// evaluated-in-false), all tree nodes.
|
||||
// construct. The format is (condition, evaluated-if-true, evaluated-in-false).
|
||||
// The first two are tree nodes, the last one can be a node, or null if there's no else.
|
||||
const CONDITIONAL = 'CONDITIONAL';
|
||||
|
||||
// LOGIC is a logic operator accepted by AFPData::boolOp. The format is
|
||||
|
|
|
@ -236,19 +236,12 @@ class AFPTreeParser {
|
|||
|
||||
$valueIfTrue = $this->doLevelConditions();
|
||||
|
||||
if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'else' ) ) {
|
||||
throw new AFPUserVisibleException( 'expectednotfound',
|
||||
$this->mPos,
|
||||
[
|
||||
'else',
|
||||
$this->mCur->type,
|
||||
$this->mCur->value
|
||||
]
|
||||
);
|
||||
if ( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'else' ) {
|
||||
$this->move();
|
||||
$valueIfFalse = $this->doLevelConditions();
|
||||
} else {
|
||||
$valueIfFalse = null;
|
||||
}
|
||||
$this->move();
|
||||
|
||||
$valueIfFalse = $this->doLevelConditions();
|
||||
|
||||
if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'end' ) ) {
|
||||
throw new AFPUserVisibleException( 'expectednotfound',
|
||||
|
|
|
@ -240,11 +240,16 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
|
|||
list( $condition, $valueIfTrue, $valueIfFalse ) = $node->children;
|
||||
$condition = $this->evalNode( $condition );
|
||||
if ( $condition->toBool() ) {
|
||||
$this->discardWithHoisting( $valueIfFalse );
|
||||
if ( $valueIfFalse !== null ) {
|
||||
$this->discardWithHoisting( $valueIfFalse );
|
||||
}
|
||||
return $this->evalNode( $valueIfTrue );
|
||||
} else {
|
||||
$this->discardWithHoisting( $valueIfTrue );
|
||||
return $this->evalNode( $valueIfFalse );
|
||||
return $valueIfFalse !== null
|
||||
? $this->evalNode( $valueIfFalse )
|
||||
// We assume null as default if the else is missing
|
||||
: new AFPData( AFPData::DNULL );
|
||||
}
|
||||
|
||||
case AFPTreeNode::ASSIGNMENT:
|
||||
|
|
|
@ -508,7 +508,8 @@ class AbuseFilterParser {
|
|||
$this->move();
|
||||
|
||||
$r1 = new AFPData( AFPData::DEMPTY );
|
||||
$r2 = new AFPData( AFPData::DEMPTY );
|
||||
// DNULL is assumed as default in case of a missing else
|
||||
$r2 = new AFPData( AFPData::DNULL );
|
||||
|
||||
$isTrue = $result->toBool();
|
||||
|
||||
|
@ -520,24 +521,16 @@ class AbuseFilterParser {
|
|||
$this->mShortCircuit = $scOrig;
|
||||
}
|
||||
|
||||
if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'else' ) ) {
|
||||
throw new AFPUserVisibleException( 'expectednotfound',
|
||||
$this->mCur->pos,
|
||||
[
|
||||
'else',
|
||||
$this->mCur->type,
|
||||
$this->mCur->value
|
||||
]
|
||||
);
|
||||
}
|
||||
$this->move();
|
||||
if ( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'else' ) {
|
||||
$this->move();
|
||||
|
||||
if ( $isTrue ) {
|
||||
$scOrig = wfSetVar( $this->mShortCircuit, $this->mAllowShort, true );
|
||||
}
|
||||
$this->doLevelConditions( $r2 );
|
||||
if ( $isTrue ) {
|
||||
$this->mShortCircuit = $scOrig;
|
||||
if ( $isTrue ) {
|
||||
$scOrig = wfSetVar( $this->mShortCircuit, $this->mAllowShort, true );
|
||||
}
|
||||
$this->doLevelConditions( $r2 );
|
||||
if ( $isTrue ) {
|
||||
$this->mShortCircuit = $scOrig;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'end' ) ) {
|
||||
|
|
|
@ -57,8 +57,6 @@ false & (
|
|||
var9 := 'foo';
|
||||
if ( 1=== 1 ) then
|
||||
( false & ( var9 := 'foobar' ) )
|
||||
else
|
||||
( 0 )
|
||||
end;
|
||||
|
||||
var1 === 1 &
|
||||
|
|
|
@ -1,2 +1,4 @@
|
|||
(if 1 then 2 else 3 end) === 2 &
|
||||
(if false then 2 else 3 end) === 3
|
||||
(if false then 2 else 3 end) === 3 &
|
||||
(if true then 3 end) === 3 &
|
||||
(if false then 3 end) === null
|
||||
|
|
Loading…
Reference in a new issue