Skip to content

Commit

Permalink
Improve URL validation for scaffold package readme section (#234)
Browse files Browse the repository at this point in the history
* Improve URL validation for scaffold package readme section

* Add feature test for sections pre, post and body
  • Loading branch information
ernilambar authored Mar 13, 2024
1 parent 5655856 commit 195ccb1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions features/scaffold-package-readme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,39 @@ Feature: Scaffold a README.md file for an existing package
Support isn't free!
"""

Scenario: Scaffold a readme with a pre, post and body for the section
Given an empty directory
And a foo/composer.json file:
"""
{
"name": "runcommand/profile",
"description": "Quickly identify what's slow with WordPress.",
"homepage": "https://runcommand.io/wp/profile/",
"extra": {
"readme": {
"contributing": {
"pre": "[Visit Site](https://example.com)",
"body": "https://gist.githubusercontent.com/danielbachhuber/bb652b1b744cea541705ee9c13605dad/raw/195c17ebb8cf25e947a9df6e02de1e96a084c287/support.md",
"post": "I am after body."
}
}
}
}
"""

When I run `wp scaffold package-readme foo`
Then the foo/README.md file should exist
And the foo/README.md file should contain:
"""
## Contributing
[Visit Site](https://example.com)
Support isn't free!
I am after body.
"""

Scenario: Scaffold a readme with custom sections
Given an empty directory
And a foo/composer.json file:
Expand Down
2 changes: 1 addition & 1 deletion src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public function package_readme( $args, $assoc_args ) {
$v = '';
if ( isset( $composer_obj['extra']['readme'][ $section ][ $k ] ) ) {
$v = $composer_obj['extra']['readme'][ $section ][ $k ];
if ( false !== strpos( $v, '://' ) ) {
if ( filter_var( $v, FILTER_VALIDATE_URL ) === $v ) {
$response = Utils\http_request( 'GET', $v );
$v = $response->body;
} elseif ( preg_match( $ext_regex, $v ) ) {
Expand Down

0 comments on commit 195ccb1

Please sign in to comment.