-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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] Fix isURL #20172
[RNMobile] Fix isURL #20172
Conversation
Changes on this PR: #19871 broke the native `is-url` version since it won't throw if the given string is not a url.
In putting together #19871, I was careful to consider that validation conform to the contract of what is considered valid per the URL standard, and only incidentally that this be fulfilled using the That said:
|
I'm glad I brought this up, because in closer inspection of the polyfill we chose to use for Edit: Reported upstream at https://github.com/Financial-Times/polyfill-library/issues/462 |
See also: https://github.com/charpeni/react-native-url-polyfill Specifically: https://github.com/charpeni/react-native-url-polyfill#why-do-we-need-this Official (?) stance: facebook/react-native#16434 (comment) |
This solves an issue with `isURL` where RN-URL is not behaving as expected. Check WordPress/gutenberg#20172
Thank you @aduth for your feedback! I've tested using Updated the PR with this change. I also added this package as deb dependency to gutenberg to run the native unit tests properly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sensible from my perspective 👍
I'll leave it to your discretion whether it needs eyes from one more familiar with mobile side of things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can you confirm: Should react-native-url-polyfill
be defined as a dependency of the url
package rather than in the root package.json
? Typically I would expect to see a package's own dependencies listed only in its own package.json
, not at the root. Unsure if this is different for React Native work.
@aduth - some updates: Talking with @hypest internally, we have decided to go back to the first proposal momentarily, in order to fix wordpress-mobile/gutenberg-mobile#1875, and then we would come back to I'll wait for your confirmation before rolling back the commits 👍 |
Is this a known upstream issue? Do we have a sense why the error is happening? If it's simplest to revert to the first proposal as a fix for wordpress-mobile/gutenberg-mobile#1875, that sounds reasonable to me. I would just be wary to not let these diverge too long, since the two implementations can have differing resulting values from its input (the earlier implementation being much more strict about "http" URLs). |
38ff0a8
to
6512ab8
Compare
Reverted to the previous proposal.
@aduth - This proposal is a bit more complex than the older implementation. I was careful to make the same set of tests implemented on the web side pass. So things like:
...will all return true. I hope this gives a bit more confidence. But it's true that there might be other urls that these implementations will return different results. There is this related issue, I think it's the same problem but haven't had much attention so far. We might need to try to push it a bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it can pass the same tests, that seems like a perfectly reasonable alternative implementation. And if it turns out not to be, then it's a clear indication that the tests could be improved. A win/win either way! (Well, except for those affected by however it might hypothetically break 😅)
Noting that this aligns to a remark I made at #19871 (comment) in the original implementation:
One advantage of having the tests is that it could support some potential future refactoring where we choose not to implement it using the
URL
constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Thank you both! 🎉 |
👋 Hey! I'm the author of react-native-url-polyfill. I flagged the issue with Hermes: facebook/hermes#193, and I fixed it in react-native-url-polyfill. Everything is now working fine with Hermes! |
gutenberg-mobile
PR: wordpress-mobile/gutenberg-mobile#1879Description
The changes on the PR #19871 to
isURL
assume that the constructor ofURL
"throws an error for an invalid URL", which is not the case for the mobile implementation.This PR brings back the previous implementation of
isURL
just for native, with a few improvements to make it behave as the new web version (tested running the same set of tests).@SergioEstevao - I remember you having some opinions about the
isURL
check, could you please take a look at this?Also @aduth - since you authored the original PR, it would be great if we could have a shared implementation on this, but from what I see, we can not trust that the URL constructor will throw.
Any improvement to the given solution is welcome!
The implemented Regex was taken from here, adding a group to match for ports.
How has this been tested?