Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional capture group to url regex in wp-env #43200

Merged

Conversation

titusdmoore
Copy link
Contributor

What?

Resolve issue where urls with query parameters won't work in wp-env using wp-env.json to include plugins or themes.

Why?

This can cause issues where adding plugins from third party developers can cause issues if they don't have their plugin added to the WordPress marketplace. My experience has been with Gravity Forms. Solves issue #43199

How?

Change the regex string that validates urls to include an optional capture group post .zip that will pass if the string has query parameters.

Testing Instructions

  1. Create wp-env.json file with plugins attribute with url values that match old pattern [url]/zip-name.zip and new pattern [url]/zip-name.zip?authAttr={attrValue}
  2. Run wp-env start
  3. Ensure that both plugin urls have been included into project and have been activated

Screenshots or screencast

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Aug 12, 2022
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @titusdmoore! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@noahtallen
Copy link
Member

noahtallen commented Aug 16, 2022

Overall, this looks good to me. Could you update the tests here?

it( 'should parse zip sources', async () => {
readFile.mockImplementation( () =>
Promise.resolve(
JSON.stringify( {
plugins: [
'https://www.example.com/test/path/to/gutenberg.zip',
'https://www.example.com/test/path/to/gutenberg.8.1.0.zip',
'https://www.example.com/test/path/to/twentytwenty.zip',
'https://www.example.com/test/path/to/twentytwenty.1.3.zip',
'https://example.com/twentytwenty.1.3.zip',
],
} )
)
);
const config = await readConfig( '.wp-env.json' );
const matchObj = {
pluginSources: [
{
type: 'zip',
url: 'https://www.example.com/test/path/to/gutenberg.zip',
path: expect.stringMatching( /^(\/|\\).*gutenberg$/ ),
basename: 'gutenberg',
},
{
type: 'zip',
url: 'https://www.example.com/test/path/to/gutenberg.8.1.0.zip',
path: expect.stringMatching(
/^(\/|\\).*gutenberg.8.1.0$/
),
basename: 'gutenberg.8.1.0',
},
{
type: 'zip',
url: 'https://www.example.com/test/path/to/twentytwenty.zip',
path: expect.stringMatching(
/^(\/|\\).*twentytwenty$/
),
basename: 'twentytwenty',
},
{
type: 'zip',
url: 'https://www.example.com/test/path/to/twentytwenty.1.3.zip',
path: expect.stringMatching(
/^(\/|\\).*twentytwenty.1.3$/
),
basename: 'twentytwenty.1.3',
},
{
type: 'zip',
url: 'https://example.com/twentytwenty.1.3.zip',
path: expect.stringMatching(
/^(\/|\\).*twentytwenty.1.3$/
),
basename: 'twentytwenty.1.3',
},
],
};
expect( config.env.development ).toMatchObject( matchObj );
expect( config.env.tests ).toMatchObject( matchObj );
} );

I would just add another entry to that array which includes some query params, and then include that entry in the matchObj

Copy link
Member

@noahtallen noahtallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you!

@noahtallen noahtallen merged commit d0220ea into WordPress:trunk Aug 16, 2022
@noahtallen noahtallen added [Type] Enhancement A suggestion for improvement. [Tool] Env /packages/env labels Aug 16, 2022
@github-actions
Copy link

Congratulations on your first merged pull request, @titusdmoore! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 14.0 milestone Aug 16, 2022
noahtallen pushed a commit that referenced this pull request Aug 16, 2022
Add optional capture group to url regex in wp-env's .zip source logic to 
download .zip's from URLs with query parameters.

Co-authored-by: Titus Moore <[email protected]>
@noahtallen noahtallen linked an issue Aug 16, 2022 that may be closed by this pull request
@titusdmoore titusdmoore deleted the bugfix/resolve-url-regex-error branch August 17, 2022 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Tool] Env /packages/env [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wp-env Including Plugins with Query Parameters Causes Error
3 participants