Skip to content

Commit 195ccb1

Browse files
authored
Improve URL validation for scaffold package readme section (#234)
* Improve URL validation for scaffold package readme section * Add feature test for sections pre, post and body
1 parent 5655856 commit 195ccb1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

features/scaffold-package-readme.feature

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,39 @@ Feature: Scaffold a README.md file for an existing package
199199
Support isn't free!
200200
"""
201201

202+
Scenario: Scaffold a readme with a pre, post and body for the section
203+
Given an empty directory
204+
And a foo/composer.json file:
205+
"""
206+
{
207+
"name": "runcommand/profile",
208+
"description": "Quickly identify what's slow with WordPress.",
209+
"homepage": "https://runcommand.io/wp/profile/",
210+
"extra": {
211+
"readme": {
212+
"contributing": {
213+
"pre": "[Visit Site](https://example.com)",
214+
"body": "https://gist.githubusercontent.com/danielbachhuber/bb652b1b744cea541705ee9c13605dad/raw/195c17ebb8cf25e947a9df6e02de1e96a084c287/support.md",
215+
"post": "I am after body."
216+
}
217+
}
218+
}
219+
}
220+
"""
221+
222+
When I run `wp scaffold package-readme foo`
223+
Then the foo/README.md file should exist
224+
And the foo/README.md file should contain:
225+
"""
226+
## Contributing
227+
228+
[Visit Site](https://example.com)
229+
230+
Support isn't free!
231+
232+
I am after body.
233+
"""
234+
202235
Scenario: Scaffold a readme with custom sections
203236
Given an empty directory
204237
And a foo/composer.json file:

src/ScaffoldPackageCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public function package_readme( $args, $assoc_args ) {
399399
$v = '';
400400
if ( isset( $composer_obj['extra']['readme'][ $section ][ $k ] ) ) {
401401
$v = $composer_obj['extra']['readme'][ $section ][ $k ];
402-
if ( false !== strpos( $v, '://' ) ) {
402+
if ( filter_var( $v, FILTER_VALIDATE_URL ) === $v ) {
403403
$response = Utils\http_request( 'GET', $v );
404404
$v = $response->body;
405405
} elseif ( preg_match( $ext_regex, $v ) ) {

0 commit comments

Comments
 (0)