Making WordPress.org

Changeset 11908


Ignore:
Timestamp:
06/09/2022 01:47:36 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Readme Parser: Be more tolerable of blank lines within the headers if it's followed by a valid header.

This allows for these edgecases to be handled:

  • "Tags: a,b,c\n\nStable Tag: 1.2"
  • "Tags: a,b,c\nStrangeHeader: true\nStable Tag: 1.2"

along with the expected and valid

  • "tags: a,b,c\nStable Tag: 1.2"

while also not discarding a Short description just because it contained a :.

Props Ipstenu for the report.
Fixes #6358.

File:
1 edited

Legend:

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

    r10573 r11908  
    238238        $headers = array();
    239239
    240         $line = $this->get_first_nonwhitespace( $contents );
     240        $line                = $this->get_first_nonwhitespace( $contents );
     241        $last_line_was_blank = false;
    241242        do {
    242243            $value = null;
    243             if ( false === strpos( $line, ':' ) ) {
    244 
    245                 // Some plugins have line-breaks within the headers.
     244            // If it doesn't look like a header value, maybe break to the next section.
     245            if ( ! str_contains( $line, ':' ) || str_starts_with( $line, '#' ) || str_starts_with( $line, '=' ) ) {
    246246                if ( empty( $line ) ) {
     247                    // Some plugins have line-breaks within the headers...
     248                    $last_line_was_blank = true;
     249                    continue;
     250                } else {
     251                    // We've hit a line that is not blank, but also doesn't look like a header, assume the Short Description and end Header parsing.
    247252                    break;
    248                 } else {
    249                     continue;
    250253                }
    251254            }
     
    254257            list( $key, $value ) = $bits;
    255258            $key                 = strtolower( trim( $key, " \t*-\r\n" ) );
     259
    256260            if ( isset( $this->valid_headers[ $key ] ) ) {
    257261                $headers[ $this->valid_headers[ $key ] ] = trim( $value );
    258             }
     262            } elseif ( $last_line_was_blank ) {
     263                // If we skipped over a blank line, and then ended up with an unexpected header, assume we parsed too far and ended up in the Short Description.
     264                // This final line will be added back into the stack after the loop for further parsing.
     265                break;
     266            }
     267
     268            $last_line_was_blank = false;
    259269        } while ( ( $line = array_shift( $contents ) ) !== null );
    260270        array_unshift( $contents, $line );
Note: See TracChangeset for help on using the changeset viewer.