Making WordPress.org


Ignore:
Timestamp:
04/06/2018 05:04:54 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Readme: Ignore invalid Requires PHP headers and add a parsing warning clarifying the expected contents.

Fixes #3551.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php

    r7021 r7049  
    8989
    9090    /**
    91      * Flag to specify that a Contributor was ignored.
    92      *
    93      * @var bool
    94      */
    95     public $contributor_ignored = false;
     91     * Warning flags which indicate specific parsing failures have occured.
     92     *
     93     * @var array
     94     */
     95    public $warnings = array();
    9696
    9797    /**
     
    244244        }
    245245        if ( ! empty( $headers['requires_php'] ) ) {
    246             $this->requires_php = $headers['requires_php'];
     246            $this->requires_php = $this->sanitize_requires_php( $headers['requires_php'] );
    247247        }
    248248        if ( ! empty( $headers['contributors'] ) ) {
     
    551551            if ( ! $user ) {
    552552                unset( $users[ $i ] );
    553                 $this->contributor_ignored = true;
     553                $this->warnings['contributor_ignored'] = true;
    554554                continue;
    555555            }
     
    580580
    581581        return $stable_tag;
     582    }
     583
     584    /**
     585     * Sanitizes the Requires PHP header to ensure that it's a valid version header.
     586     *
     587     * @param string $version
     588     * @return string The sanitized $version
     589     */
     590    protected function sanitize_requires_php( $version ) {
     591        $version = trim( $version );
     592
     593        // x.y or x.y.z
     594        if ( $version && ! preg_match( '!^\d+(\.\d+){1,2}$!', $version ) ) {
     595            $this->warnings['requires_php_ignored'] = true;
     596            // Ignore the readme value.
     597            $version = '';
     598        }
     599
     600        return $version;
    582601    }
    583602
Note: See TracChangeset for help on using the changeset viewer.