Changeset 3163
- Timestamp:
- 05/18/2016 02:08:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-readme-parser.php
r2997 r3163 56 56 57 57 public function __construct( $file ) { 58 $this->parse_readme( $file ); 58 if ( $file ) { 59 $this->parse_readme( $file ); 60 } 59 61 } 60 62 … … 81 83 if ( 'plugin name' == strtolower( $this->name ) ) { 82 84 $this->name = $line = $this->get_first_nonwhitespace( $contents ); 83 // Ensure that the line read wasn't an actual header 84 if ( preg_match( '~^(' . implode( '|', array_keys( $this->valid_headers ) ) . ')\s*:~i', $line ) ) {85 // Ensure that the line read wasn't an actual header or description 86 if ( strlen( $line ) > 50 || preg_match( '~^(' . implode( '|', array_keys( $this->valid_headers ) ) . ')\s*:~i', $line ) ) { 85 87 $this->name = false; 86 88 array_unshift( $contents, $line ); … … 128 130 } 129 131 if ( ! empty( $headers['stable_tag'] ) ) { 130 $this->stable_tag = $ headers['stable_tag'];132 $this->stable_tag = $this->sanitize_stable_tag( $headers['stable_tag'] ); 131 133 } 132 134 if ( ! empty( $headers['donate_link'] ) ) { … … 365 367 } 366 368 369 /** 370 * Sanitize the provided stable tag to something we expect. 371 * 372 * @param string $stable_tag the raw Stable Tag line from the readme. 373 * @return string The sanitized $stable_tag. 374 */ 375 protected function sanitize_stable_tag( $stable_tag ) { 376 $stable_tag = trim( $stable_tag ); 377 $stable_tag = trim( $stable_tag, '"\'' ); // "trunk" 378 $stable_tag = preg_replace( '!^/?tags/!i', '', $stable_tag ); // "tags/1.2.3" 379 $stable_tag = preg_replace( '![^a-z0-9_.-]!i', '', $stable_tag ); 380 381 return $stable_tag; 382 } 383 367 384 protected function parse_markdown( $text ) { 368 385 static $markdown = null;
Note: See TracChangeset
for help on using the changeset viewer.