From e67df1ecac8ea841aee6aed0afcd42433381144d Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 25 Mar 2008 05:17:42 +0000 Subject: [PATCH] Fixed r32391 -- the media handler may define parameters, and the parser has no right or ability to validate those parameters. The handler does in fact provide a validateParam() function for precisely this purpose -- to signal to the parser which parameters should be silently ignored. In particular, the thumbtime parameter in OggHandler would have been broken by this commit. --- includes/Parser.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index bbe1fedc7b..1fcaccd027 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -4416,23 +4416,36 @@ class Parser 'horizAlign' => array(), 'vertAlign' => array() ); foreach( $parts as $part ) { list( $magicName, $value ) = $mwArray->matchVariableStartToEnd( $part ); - # (bug 13436) If $value is non-numeric, assume it's a caption - if( isset( $paramMap[$magicName] ) && - ( $value === false || is_numeric($value) ) ) { + $validated = false; + if( isset( $paramMap[$magicName] ) ) { list( $type, $paramName ) = $paramMap[$magicName]; - $params[$type][$paramName] = $value; - + // Special case; width and height come in one variable together if( $type == 'handler' && $paramName == 'width' ) { $m = array(); if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $value, $m ) ) { $params[$type]['width'] = intval( $m[1] ); $params[$type]['height'] = intval( $m[2] ); - } else { + $validated = true; + } elseif ( is_numeric( $value ) ) { $params[$type]['width'] = intval( $value ); + $validated = true; + } // else no validation -- bug 13436 + } else { + if ( $type == 'handler' ) { + # Validate handler parameter + $validated = $handler->validateParam( $paramName, $value ); + } else { + # Validate internal parameters + $validated = ( $value === false || is_numeric( $value ) ); + } + + if ( $validated ) { + $params[$type][$paramName] = $value; } } - } else { + } + if ( !$validated ) { $caption = $part; } } @@ -4445,15 +4458,6 @@ class Parser $params['frame']['valign'] = key( $params['vertAlign'] ); } - # Validate the handler parameters - if ( $handler ) { - foreach ( $params['handler'] as $name => $value ) { - if ( !$handler->validateParam( $name, $value ) ) { - unset( $params['handler'][$name] ); - } - } - } - # Strip bad stuff out of the alt text $alt = $this->replaceLinkHoldersText( $caption ); -- 2.20.1