Make validation for page more strict on djvu to take only numbers
authorBrian Wolff <bawolff+wn@gmail.com>
Thu, 15 May 2014 00:48:43 +0000 (21:48 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Thu, 15 May 2014 00:48:43 +0000 (21:48 -0300)
This change causes wiki syntax like
 [[File:Foo.djvu|thumb|Page 7 of document]]
to be interpreted as a caption instead, of saying select page 7
of the djvu. Previously it eventually ran intval( '7 of document' ),
so flipped to page 7.

Only possible downside I could see is this would cause things like
left-to-right marks and weird unicode spaces to no longer be ignored.
I don't think that's a big deal.

Change-Id: Ie8c953009a38557876a274bf0f71ab470f66ef4e

includes/media/DjVu.php

index aeba647..566efb2 100644 (file)
@@ -73,6 +73,11 @@ class DjVuHandler extends ImageHandler {
         * @return bool
         */
        function validateParam( $name, $value ) {
+               if ( $name === 'page' && trim( $value ) !== (string) intval( $value ) ) {
+                       // Extra junk on the end of page, probably actually a caption
+                       // e.g. [[File:Foo.djvu|thumb|Page 3 of the document shows foo]]
+                       return false;
+               }
                if ( in_array( $name, array( 'width', 'height', 'page' ) ) ) {
                        if ( $value <= 0 ) {
                                return false;