Merged
Conversation
DiegoRBaquero
approved these changes
May 20, 2021
Contributor
|
How about something like this instead: str = 'udp://github.com'
url = new URL(str.replace(/^udp:/, 'http:'))
if (str.match(/^udp:/)) {
Object.defineProperties(url, {
href: { value: url.href.replace(/^http/, 'udp') },
protocol: { value: url.protocol.replace(/^http/, 'udp') },
origin: { value: url.origin.replace(/^http/, 'udp') }
})
}You will keep it as a URL instances and get support for the rest of the class (serialize to string, instance check, searchParams) |
Member
Author
|
Neat, thanks @jimmywarting! I have updated the PR. |
feross
approved these changes
May 21, 2021
| exports.parseUrl = function (str) { | ||
| const url = new URL(str.replace(/^udp:/, 'http:')) | ||
|
|
||
| if (str.match(/^udp:/)) { |
Member
There was a problem hiding this comment.
Nit: Since it's just being used to get a boolean, I prefer to use /^udp:/.test(str).
Member
|
🎉 This PR is included in version 9.17.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[X] Bug fix
[ ] New feature
[ ] Other, please explain:
What changes did you make? (Give an overview)
As noted in the comments of the code, there is still a bug in Chrome and Firefox which doesn't correctly parse UDP urls.
The previous code didn't handle the UDP case in the first parsing of the URL:
bittorrent-tracker/client.js
Line 89 in 2a12b75
parseUrlin thecommonfile to handle the special case for UDP urls, so that the code can be reused wherever is necessary.Which issue (if any) does this pull request address?
Fixes webtorrent/webtorrent#2066
Is there anything you'd like reviewers to focus on?
Let me know if the implementation of
parseUrlcan be improved