Skip to content

Commit 1dba89c

Browse files
committed
update class-parser
1 parent 1ac76f4 commit 1dba89c

File tree

4 files changed

+55
-22
lines changed

4 files changed

+55
-22
lines changed

composer.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/afragen/wordpress-plugin-readme-parser/class-parser.php

+44-11
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,34 @@ protected function parse_readme_contents( $contents ) {
227227
if ( 'plugin name' == strtolower( $this->name ) ) {
228228
$this->warnings['invalid_plugin_name_header'] = true;
229229

230-
$this->name = $line = $this->get_first_nonwhitespace( $contents );
230+
$this->name = false;
231+
$line = $this->get_first_nonwhitespace( $contents );
231232

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

239+
// It's possible to leave the plugin name header off entirely.
240+
if ( $this->parse_possible_header( $this->name, true /* only valid headers */ ) ) {
241+
array_unshift( $contents, $line );
242+
243+
$this->warnings['invalid_plugin_name_header'] = true;
244+
$this->name = false;
245+
}
246+
239247
// Parse headers.
240248
$headers = array();
241249

242250
$line = $this->get_first_nonwhitespace( $contents );
243251
$last_line_was_blank = false;
244252
do {
245-
$value = null;
253+
$value = null;
254+
$header = $this->parse_possible_header( $line );
255+
246256
// If it doesn't look like a header value, maybe break to the next section.
247-
if ( ! str_contains( $line, ':' ) || str_starts_with( $line, '#' ) || str_starts_with( $line, '=' ) ) {
257+
if ( ! $header ) {
248258
if ( empty( $line ) ) {
249259
// Some plugins have line-breaks within the headers...
250260
$last_line_was_blank = true;
@@ -255,12 +265,10 @@ protected function parse_readme_contents( $contents ) {
255265
}
256266
}
257267

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

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

532+
/**
533+
* Parse a line to see if it's a header.
534+
*
535+
* @access protected
536+
*
537+
* @param string $line The line from the readme to parse.
538+
* @param bool $only_valid Whether to only return a valid known header.
539+
* @return false|array
540+
*/
541+
protected function parse_possible_header( $line, $only_valid = false ) {
542+
if ( ! str_contains( $line, ':' ) || str_starts_with( $line, '#' ) || str_starts_with( $line, '=' ) ) {
543+
return false;
544+
}
545+
546+
list( $key, $value ) = explode( ':', $line, 2 );
547+
$key = strtolower( trim( $key, " \t*-\r\n" ) );
548+
$value = trim( $value, " \t*-\r\n" );
549+
550+
if ( $only_valid && ! isset( $this->valid_headers[ $key ] ) ) {
551+
return false;
552+
}
553+
554+
return [ $key, $value ];
555+
}
556+
524557
/**
525558
* @access protected
526559
*

vendor/composer/installed.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@
5757
"source": {
5858
"type": "git",
5959
"url": "https://github.com/afragen/wordpress-plugin-readme-parser.git",
60-
"reference": "2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54"
60+
"reference": "0dc64ee6d4cb6d32e3855d016763d9bd08652e0f"
6161
},
6262
"dist": {
6363
"type": "zip",
64-
"url": "https://api.github.com/repos/afragen/wordpress-plugin-readme-parser/zipball/2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54",
65-
"reference": "2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54",
64+
"url": "https://api.github.com/repos/afragen/wordpress-plugin-readme-parser/zipball/0dc64ee6d4cb6d32e3855d016763d9bd08652e0f",
65+
"reference": "0dc64ee6d4cb6d32e3855d016763d9bd08652e0f",
6666
"shasum": ""
6767
},
6868
"require": {
6969
"erusev/parsedown": "^1.7",
7070
"php": ">=5.4"
7171
},
72-
"time": "2024-01-25T16:41:35+00:00",
72+
"time": "2024-02-02T17:46:48+00:00",
7373
"default-branch": true,
7474
"type": "library",
7575
"installation-source": "dist",

vendor/composer/installed.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'name' => 'afragen/git-updater',
44
'pretty_version' => 'dev-develop',
55
'version' => 'dev-develop',
6-
'reference' => '12a812cee5d960c21e94197781839d5bdeee45d2',
6+
'reference' => '1ac76f41f4d1736b801594dc0ffe951ab4499ba4',
77
'type' => 'wordpress-plugin',
88
'install_path' => __DIR__ . '/../../',
99
'aliases' => array(),
@@ -13,7 +13,7 @@
1313
'afragen/git-updater' => array(
1414
'pretty_version' => 'dev-develop',
1515
'version' => 'dev-develop',
16-
'reference' => '12a812cee5d960c21e94197781839d5bdeee45d2',
16+
'reference' => '1ac76f41f4d1736b801594dc0ffe951ab4499ba4',
1717
'type' => 'wordpress-plugin',
1818
'install_path' => __DIR__ . '/../../',
1919
'aliases' => array(),
@@ -33,7 +33,7 @@
3333
'afragen/wordpress-plugin-readme-parser' => array(
3434
'pretty_version' => 'dev-master',
3535
'version' => 'dev-master',
36-
'reference' => '2f4fbe89bb7ffaf905eb28b385b7d1def4a83f54',
36+
'reference' => '0dc64ee6d4cb6d32e3855d016763d9bd08652e0f',
3737
'type' => 'library',
3838
'install_path' => __DIR__ . '/../afragen/wordpress-plugin-readme-parser',
3939
'aliases' => array(

0 commit comments

Comments
 (0)