Skip to content

Commit 15a712e

Browse files
Update URL.js
1 parent 6655e30 commit 15a712e

File tree

1 file changed

+13
-8
lines changed
  • packages/react-native/Libraries/Blob

1 file changed

+13
-8
lines changed

packages/react-native/Libraries/Blob/URL.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* @flow
99
*/
1010

11-
import type Blob from './Blob';
11+
import type Blob from 'react-native/Libraries/Blob/Blob';
1212

13-
import NativeBlobModule from './NativeBlobModule';
13+
import NativeBlobModule from 'react-native/Libraries/Blob/NativeBlobModule';
1414

1515
let BLOB_URL_PREFIX = null;
1616

@@ -52,7 +52,7 @@ if (
5252
* ```
5353
*/
5454

55-
export {URLSearchParams} from './URLSearchParams';
55+
export {URLSearchParams} from 'react-native/Libraries/Blob/URLSearchParams';
5656

5757
function validateBaseUrl(url: string) {
5858
// from this MIT-licensed gist: https://gist.github.com/dperini/729294
@@ -72,6 +72,7 @@ export class URL {
7272
return `${BLOB_URL_PREFIX}${blob.data.blobId}?offset=${blob.data.offset}&size=${blob.size}`;
7373
}
7474

75+
7576
static revokeObjectURL(url: string) {
7677
// Do nothing.
7778
}
@@ -112,13 +113,14 @@ export class URL {
112113
}
113114

114115
get host(): string {
115-
const hostMatch = this._url.match(/^https?:\/\/([^:/?#]+)/);
116+
const hostMatch = this._url.match(/^https?:\/\/(?:[^@]+@)?([^:/?#]+)/);
116117
const portMatch = this._url.match(/:(\d+)(?=[/?#]|$)/);
118+
117119
return hostMatch ? hostMatch[1] + (portMatch ? `:${portMatch[1]}` : '') : '';
118120
}
119121

120122
get hostname(): string {
121-
const hostnameMatch = this._url.match(/^https?:\/\/([^:/?#]+)/);
123+
const hostnameMatch = this._url.match(/^https?:\/\/(?:[^@]+@)?([^:/?#]+)/);
122124
return hostnameMatch ? hostnameMatch[1] : '';
123125
}
124126

@@ -136,6 +138,12 @@ export class URL {
136138
return passwordMatch ? passwordMatch[1] : '';
137139
}
138140

141+
get username(): string {
142+
143+
const usernameMatch = this._url.match(/^https?:\/\/([^:@]+)(?::[^@]*)?@/);
144+
return usernameMatch ? usernameMatch[1] : '';
145+
}
146+
139147
get pathname(): string {
140148
const pathMatch = this._url.match(/https?:\/\/[^/]+(\/[^?#]*)?/);
141149
return pathMatch ? pathMatch[1] || '/' : '/';
@@ -177,7 +185,4 @@ export class URL {
177185
return this._url + separator + instanceString;
178186
}
179187

180-
get username(): string {
181-
throw new Error('URL.username is not implemented');
182-
}
183188
}

0 commit comments

Comments
 (0)