Make WordPress Core


Ignore:
Timestamp:
03/27/2014 08:39:08 PM (11 years ago)
Author:
wonderboymusic
Message:

In multi_resize() image editor methods, assert that null can only be passed for one of the arguments, not both. Add a lot more unit test assertions to ensure this.

Props pbearne, DH-Shredder.
Fixes #26823.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r26851 r27794  
    212212     * Resizes current image.
    213213     *
    214      * @since 3.5.0
    215      * @access public
    216      *
    217      * @param int $max_w
    218      * @param int $max_h
    219      * @param boolean $crop
     214     * At minimum, either a height or width must be provided.
     215     * If one of the two is set to null, the resize will
     216     * maintain aspect ratio according to the provided dimension.
     217     *
     218     * @since 3.5.0
     219     * @access public
     220     *
     221     * @param  int|null $max_w Image width.
     222     * @param  int|null $max_h Image height.
     223     * @param  boolean  $crop
    220224     * @return boolean|WP_Error
    221225     */
     
    256260     *     An array of image size arrays. Default sizes are 'small', 'medium', 'large'.
    257261     *
     262     *     Either a height or width must be provided.
     263     *     If one of the two is set to null, the resize will
     264     *     maintain aspect ratio according to the provided dimension.
     265     *
    258266     *     @type array $size {
    259      *         @type int  $width Image width.
    260      *         @type int  $height Image height.
     267     *         @type int  ['width']  Optional. Image width.
     268     *         @type int  ['height'] Optional. Image height.
    261269     *         @type bool $crop   Optional. Whether to crop the image. Default false.
    262270     *     }
    263271     * }
    264      * @return array An array of resized images metadata by size.
     272     * @return array An array of resized images' metadata by size.
    265273     */
    266274    public function multi_resize( $sizes ) {
     
    273281                $this->image = $orig_image->getImage();
    274282
    275             if ( ! ( isset( $size_data['width'] ) && isset( $size_data['height'] ) ) )
     283            if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
    276284                continue;
    277 
    278             if ( ! isset( $size_data['crop'] ) )
     285            }
     286
     287            if ( ! isset( $size_data['width'] ) ) {
     288                $size_data['width'] = null;
     289            }
     290            if ( ! isset( $size_data['height'] ) ) {
     291                $size_data['height'] = null;
     292            }
     293
     294            if ( ! isset( $size_data['crop'] ) ) {
    279295                $size_data['crop'] = false;
     296            }
    280297
    281298            $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
Note: See TracChangeset for help on using the changeset viewer.