diff --git a/lib/common.js b/lib/common.js index f6c9f1e..105f43a 100644 --- a/lib/common.js +++ b/lib/common.js @@ -32,22 +32,17 @@ exports.hexToBinary = function (str) { // - Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=734880 // - Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1374505 exports.parseUrl = function (str) { - const isUDP = str.match(/^udp:/) - const parsedUrl = (isUDP) ? new URL(str.replace(/^udp:/, 'http:')) : new URL(str) + const url = new URL(str.replace(/^udp:/, 'http:')) - return { - hash: parsedUrl.hash, - host: parsedUrl.host, - hostname: parsedUrl.hostname, - href: isUDP ? parsedUrl.href.replace(/^http:/, 'udp:') : parsedUrl.href, - origin: isUDP ? parsedUrl.origin.replace(/^http:/, 'udp:') : parsedUrl.origin, - password: parsedUrl.password, - pathname: parsedUrl.pathname, - port: parsedUrl.port, - protocol: isUDP ? 'udp:' : parsedUrl.protocol, - search: parsedUrl.search, - username: parsedUrl.username + 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') } + }) } + + return url } const config = require('./common-node')