Skip to content

Commit

Permalink
update class-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
afragen committed Feb 4, 2024
1 parent 1ac76f4 commit 1dba89c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 44 additions & 11 deletions vendor/afragen/wordpress-plugin-readme-parser/class-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,34 @@ protected function parse_readme_contents( $contents ) {
if ( 'plugin name' == strtolower( $this->name ) ) {
$this->warnings['invalid_plugin_name_header'] = true;

$this->name = $line = $this->get_first_nonwhitespace( $contents );
$this->name = false;
$line = $this->get_first_nonwhitespace( $contents );

// Ensure that the line read wasn't an actual header or description.
if ( strlen( $line ) > 50 || preg_match( '~^(' . implode( '|', array_keys( $this->valid_headers ) ) . ')\s*:~i', $line ) ) {
$this->name = false;
array_unshift( $contents, $line );
// Ensure that the line read doesn't look like a description.
if ( strlen( $line ) < 50 && ! $this->parse_possible_header( $line, true /* only valid headers */ ) ) {
$this->name = $this->sanitize_text( trim( $line, "#= \t\0\x0B" ) );
}
}

// It's possible to leave the plugin name header off entirely.
if ( $this->parse_possible_header( $this->name, true /* only valid headers */ ) ) {
array_unshift( $contents, $line );

$this->warnings['invalid_plugin_name_header'] = true;
$this->name = false;
}

// Parse headers.
$headers = array();

$line = $this->get_first_nonwhitespace( $contents );
$last_line_was_blank = false;
do {
$value = null;
$value = null;
$header = $this->parse_possible_header( $line );

// If it doesn't look like a header value, maybe break to the next section.
if ( ! str_contains( $line, ':' ) || str_starts_with( $line, '#' ) || str_starts_with( $line, '=' ) ) {
if ( ! $header ) {
if ( empty( $line ) ) {
// Some plugins have line-breaks within the headers...
$last_line_was_blank = true;
Expand All @@ -255,12 +265,10 @@ protected function parse_readme_contents( $contents ) {
}
}

$bits = explode( ':', trim( $line ), 2 );
list( $key, $value ) = $bits;
$key = strtolower( trim( $key, " \t*-\r\n" ) );
list( $key, $value ) = $header;

if ( isset( $this->valid_headers[ $key ] ) ) {
$headers[ $this->valid_headers[ $key ] ] = trim( $value );
$headers[ $this->valid_headers[ $key ] ] = $value;
} elseif ( $last_line_was_blank ) {
// 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.
// This final line will be added back into the stack after the loop for further parsing.
Expand Down Expand Up @@ -521,6 +529,31 @@ protected function trim_length( $desc, $length = 150 ) {
return trim( $desc );
}

/**
* Parse a line to see if it's a header.
*
* @access protected
*
* @param string $line The line from the readme to parse.
* @param bool $only_valid Whether to only return a valid known header.
* @return false|array
*/
protected function parse_possible_header( $line, $only_valid = false ) {
if ( ! str_contains( $line, ':' ) || str_starts_with( $line, '#' ) || str_starts_with( $line, '=' ) ) {
return false;
}

list( $key, $value ) = explode( ':', $line, 2 );
$key = strtolower( trim( $key, " \t*-\r\n" ) );
$value = trim( $value, " \t*-\r\n" );

if ( $only_valid && ! isset( $this->valid_headers[ $key ] ) ) {
return false;
}

return [ $key, $value ];
}

/**
* @access protected
*
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@
"source": {
"type": "git",
"url": "https://github.com/afragen/wordpress-plugin-readme-parser.git",
"reference": "2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54"
"reference": "0dc64ee6d4cb6d32e3855d016763d9bd08652e0f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/afragen/wordpress-plugin-readme-parser/zipball/2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54",
"reference": "2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54",
"url": "https://api.github.com/repos/afragen/wordpress-plugin-readme-parser/zipball/0dc64ee6d4cb6d32e3855d016763d9bd08652e0f",
"reference": "0dc64ee6d4cb6d32e3855d016763d9bd08652e0f",
"shasum": ""
},
"require": {
"erusev/parsedown": "^1.7",
"php": ">=5.4"
},
"time": "2024-01-25T16:41:35+00:00",
"time": "2024-02-02T17:46:48+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",
Expand Down
6 changes: 3 additions & 3 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'afragen/git-updater',
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '12a812cee5d960c21e94197781839d5bdeee45d2',
'reference' => '1ac76f41f4d1736b801594dc0ffe951ab4499ba4',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'afragen/git-updater' => array(
'pretty_version' => 'dev-develop',
'version' => 'dev-develop',
'reference' => '12a812cee5d960c21e94197781839d5bdeee45d2',
'reference' => '1ac76f41f4d1736b801594dc0ffe951ab4499ba4',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -33,7 +33,7 @@
'afragen/wordpress-plugin-readme-parser' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54',
'reference' => '0dc64ee6d4cb6d32e3855d016763d9bd08652e0f',
'type' => 'library',
'install_path' => __DIR__ . '/../afragen/wordpress-plugin-readme-parser',
'aliases' => array(
Expand Down

0 comments on commit 1dba89c

Please sign in to comment.