Merge "Add a new data type for non-initialized stuff"

This commit is contained in:
jenkins-bot 2019-07-09 08:58:48 +00:00 committed by Gerrit Code Review
commit 35ab35978b
3 changed files with 8 additions and 5 deletions

View file

@ -8,6 +8,9 @@ class AFPData {
const DBOOL = 'bool';
const DFLOAT = 'float';
const DARRAY = 'array';
// Special purpose type for non-initialized stuff
// @todo WIP, still equivalent to null for now
const DNONE = 'null';
// Translation table mapping shell-style wildcards to PCRE equivalents.
// Derived from <http://www.php.net/manual/en/function.fnmatch.php#100207>
@ -36,7 +39,7 @@ class AFPData {
* @param string $type
* @param mixed|null $val
*/
public function __construct( $type = self::DNULL, $val = null ) {
public function __construct( $type = self::DNONE, $val = null ) {
$this->type = $type;
$this->data = $val;
}
@ -63,7 +66,7 @@ class AFPData {
}
return new AFPData( self::DARRAY, $result );
case 'NULL':
return new AFPData();
return new AFPData( self::DNULL );
default:
throw new AFPException(
'Data type ' . gettype( $var ) . ' is not supported by AbuseFilter'
@ -89,7 +92,7 @@ class AFPData {
}
if ( $target === self::DNULL ) {
// We don't expose any method to cast to null. And, actually, should we?
return new AFPData();
return new AFPData( self::DNULL );
}
if ( $orig->type === self::DARRAY ) {

View file

@ -104,7 +104,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
case "false":
return new AFPData( AFPData::DBOOL, false );
case "null":
return new AFPData();
return new AFPData( AFPData::DNULL );
}
// Fallthrough intended
default:

View file

@ -851,7 +851,7 @@ class AbuseFilterParser {
} elseif ( $tok === "false" ) {
$result = new AFPData( AFPData::DBOOL, false );
} elseif ( $tok === "null" ) {
$result = new AFPData();
$result = new AFPData( AFPData::DNULL );
} else {
throw new AFPUserVisibleException(
'unrecognisedkeyword',