Changeset 7874 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
- Timestamp:
- 11/20/2018 05:36:35 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
r7697 r7874 238 238 } 239 239 if ( ! empty( $headers['requires'] ) ) { 240 $this->requires = $ headers['requires'];240 $this->requires = $this->sanitize_requires_version( $headers['requires'] ); 241 241 } 242 242 if ( ! empty( $headers['tested'] ) ) { 243 $this->tested = $ headers['tested'];243 $this->tested = $this->sanitize_tested_version( $headers['tested'] ); 244 244 } 245 245 if ( ! empty( $headers['requires_php'] ) ) { … … 581 581 // x.y or x.y.z 582 582 if ( $version && ! preg_match( '!^\d+(\.\d+){1,2}$!', $version ) ) { 583 $this->warnings['requires_php_ ignored'] = true;583 $this->warnings['requires_php_header_ignored'] = true; 584 584 // Ignore the readme value. 585 585 $version = ''; 586 } 587 588 return $version; 589 } 590 591 /** 592 * Sanitizes the Tested header to ensure that it's a valid version header. 593 * 594 * @param string $version 595 * @return string The sanitized $version 596 */ 597 protected function sanitize_tested_version( $version ) { 598 $version = trim( $version ); 599 600 if ( $version ) { 601 602 // Handle the edge-case of 'WordPress 5.0' and 'WP 5.0' for historical purposes. 603 $strip_phrases = [ 604 'WordPress', 605 'WP', 606 ]; 607 $version = trim( str_ireplace( $strip_phrases, '', $version ) ); 608 609 // Strip off any -alpha, -RC, -beta suffixes, as these complicate comparisons and are rarely used. 610 list( $version, ) = explode( '-', $version ); 611 612 if ( 613 // x.y or x.y.z 614 ! preg_match( '!^\d+\.\d(\.\d+)?$!', $version ) || 615 // Allow plugins to mark themselves as compatible with Stable+0.1 (trunk/master) but not higher 616 defined( 'WP_CORE_STABLE_BRANCH' ) && ( (float)$version > (float)WP_CORE_STABLE_BRANCH+0.1 ) 617 ) { 618 $this->warnings['tested_header_ignored'] = true; 619 // Ignore the readme value. 620 $version = ''; 621 } 622 } 623 624 return $version; 625 } 626 627 /** 628 * Sanitizes the Requires at least header to ensure that it's a valid version header. 629 * 630 * @param string $version 631 * @return string The sanitized $version 632 */ 633 protected function sanitize_requires_version( $version ) { 634 $version = trim( $version ); 635 636 if ( $version ) { 637 638 // Handle the edge-case of 'WordPress 5.0' and 'WP 5.0' for historical purposes. 639 $strip_phrases = [ 640 'WordPress', 641 'WP', 642 'or higher', 643 'and above', 644 '+', 645 ]; 646 $version = trim( str_ireplace( $strip_phrases, '', $version ) ); 647 648 // Strip off any -alpha, -RC, -beta suffixes, as these complicate comparisons and are rarely used. 649 list( $version, ) = explode( '-', $version ); 650 651 if ( 652 // x.y or x.y.z 653 ! preg_match( '!^\d+\.\d(\.\d+)?$!', $version ) || 654 // Allow plugins to mark themselves as requireing Stable+0.1 (trunk/master) but not higher 655 defined( 'WP_CORE_STABLE_BRANCH' ) && ( (float)$version > (float)WP_CORE_STABLE_BRANCH+0.1 ) 656 ) { 657 $this->warnings['requires_header_ignored'] = true; 658 // Ignore the readme value. 659 $version = ''; 660 } 586 661 } 587 662
Note: See TracChangeset
for help on using the changeset viewer.