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

RNMobile: Detect and avoid invalid media URLs in VideoPress v5 block #35961

Merged
merged 3 commits into from Feb 27, 2024

Conversation

SiobhyB
Copy link
Contributor

@SiobhyB SiobhyB commented Feb 26, 2024

At the moment, adding invalid URLs, such as h://a-path.com, to the VideoPress v5 block fails silently on mobile. A similar issue has been known to cause the crash in wordpress-mobile/gutenberg-mobile#6233 in similar blocks in the past. Although I could not reproduce the crash, this PR mitigate the risk and also ensures a helpful error message is displayed if a user enters an invalid URL.

Proposed changes:

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

Does this pull request change what data or activity we track or use?

No, it does not.

Testing instructions:

  • Within the app, select a site that defaults to using VideoPress v5, i.e. a Simple dotcom site, an Atomic site with VideoPress enabled, or a Jetpack-connected site.
  • Navigate to the site's post editor and add a Video block.
  • Select "Insert from URL."
  • Type an invalid URL, e.g. h://wordpress.org/video.mp4.
  • Dismiss the bottom sheet.
  • Verify the app does not crash and a helpful message is displayed.

@SiobhyB SiobhyB added [Type] Bug When a feature is broken and / or not performing as intended [Block] VideoPress labels Feb 26, 2024
Copy link
Contributor

github-actions bot commented Feb 26, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the rnmobile/detect-invalid-urls branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack rnmobile/detect-invalid-urls
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Feb 26, 2024
Copy link
Contributor

github-actions bot commented Feb 26, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for March 5, 2024 (scheduled code freeze on March 4, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@SiobhyB SiobhyB marked this pull request as ready for review February 26, 2024 18:39
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

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

LGTM. The testing instructions succeeded. 🚀

Although I could not reproduce the crash, this PR mitigate the risk and also ensures a helpful error message is displayed if a user enters an invalid URL.

I'm not sure what your specific testing environment entailed, but I was able to reproduce the crash after reverting your proposed changes and performing the testing instructions.

Revert Diff
diff --git a/projects/plugins/jetpack/extensions/blocks/videopress/edit.native.js b/projects/plugins/jetpack/extensions/blocks/videopress/edit.native.js
index e81a5d0df3..63e35295f3 100644
--- a/projects/plugins/jetpack/extensions/blocks/videopress/edit.native.js
+++ b/projects/plugins/jetpack/extensions/blocks/videopress/edit.native.js
@@ -206,7 +206,7 @@ class VideoPressEdit extends Component {
 	onSelectURL( url ) {
 		const { createErrorNotice, setAttributes, onReplace } = this.props;
 
-		if ( isURL( url ) && /^https?:/.test( getProtocol( url ) ) ) {
+		if ( isURL( url ) ) {
 			// Check if there's an embed block that handles this URL.
 			const embedBlock = createVideoPressEmbedBlock( {
 				attributes: { url },

It is worth noting that the referenced crash only occurs on iOS devices. And for the specific context of the VideoPress block — i.e., the focus of this PR — the crash would only occur on a build including #35637.

@SiobhyB
Copy link
Contributor Author

SiobhyB commented Feb 27, 2024

@dcalhoun, ah, I had missed that this was iOS-specific and had been testing on Android. With that added context, I can confirm I can reproduce the crash on iOS. Thank you for the review and documenting the crash!

@github-actions github-actions bot added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 27, 2024
@SiobhyB SiobhyB merged commit 7194ccb into trunk Feb 27, 2024
54 checks passed
@SiobhyB SiobhyB deleted the rnmobile/detect-invalid-urls branch February 27, 2024 10:20
@github-actions github-actions bot added this to the jetpack/13.2 milestone Feb 27, 2024
@github-actions github-actions bot removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] VideoPress [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants