From d57db920c3f6e3e01ad9ce9c3d5a8120f183e655 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Tue, 10 May 2005 02:15:16 +0000 Subject: [PATCH] * Not returning true for whitespace ASCII tags (I found quite a few in my tests) * isRational and isSrational now include a check to make sure they're being fed a fraction, spewed errors otherwise. * (S)rational numbers are now converted to intergers/floats --- includes/Exif.php | 48 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/includes/Exif.php b/includes/Exif.php index f62dbc80ab..593096c0e5 100644 --- a/includes/Exif.php +++ b/includes/Exif.php @@ -316,7 +316,10 @@ class Exif { function isASCII( $in ) { wfDebug("Exif::isASCII: input was '$in'\n"); - return true; // TODO: FIXME + if ( preg_match( "/^\s*$/", $in ) ) { + return false; + } + return true; } function isShort( $in ) { @@ -343,13 +346,18 @@ class Exif { function isRational( $in ) { $fname = 'isRational'; - $a = explode( '/', $in, 2 ); - if ( $this->isLong( $a[0] ) && $this->isLong( $a[1] ) ) { - wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n"); - return true; - } else { - wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n"); + if ( strpos( $in, '/' ) === false ) { + wfDebug("Exif::$fname: fed a non-fraction value: (type: " . gettype( $in ) . "; data: '$in')\n"); return false; + } else { + $a = explode( '/', $in, 2 ); + if ( $this->isLong( $a[0] ) && $this->isLong( $a[1] ) ) { + wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n"); + return true; + } else { + wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n"); + return false; + } } } @@ -363,7 +371,11 @@ class Exif { function isUndefined( $in ) { $fname = 'isUndefined'; wfDebug("Exif::$fname: input was '$in'\n"); - return false; + if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion + return true; + } else { + return false; + } } function isSlong( $in ) { @@ -379,13 +391,18 @@ class Exif { function isSrational( $in ) { $fname = 'isSrational'; - $a = explode( '/', $in, 2 ); - if ( $this->isSlong( $a[0] ) && $this->isSlong( $a[1] ) ) { - wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n"); - return true; + if ( strpos( $in, '/' ) === false ) { + wfDebug("Exif::$fname: fed a non-fraction value: (type: " . gettype( $in ) . "; data: '$in')\n"); + return false; } else { - wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n"); - return false; + $a = explode( '/', $in, 2 ); + if ( $this->isSlong( $a[0] ) && $this->isSlong( $a[1] ) ) { + wfDebug("Exif::$fname: accepted: '$in' (type: " . gettype( $in ) . ")\n"); + return true; + } else { + wfDebug("Exif::$fname: rejected: '$in' (type: " . gettype( $in ) . ")\n"); + return false; + } } } /**#@-*/ @@ -720,6 +737,9 @@ class Exif { case 'Software': return wfMsg( strtolower( "exif-$tag-value" ), $val ); default: + if ( preg_match( '/^(\d+)\/(\d+)$/', $val, $m ) ) { + return $m[2] != 0 ? $m[1]/$m[2] : $val; + } return $val; } } -- 2.20.1