Skip to content

Commit a6665a3

Browse files
Update URL.js
1 parent d2dd122 commit a6665a3

File tree

1 file changed

+6
-12
lines changed
  • packages/react-native/Libraries/Blob

1 file changed

+6
-12
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type Blob from './Blob';
1212

1313
import NativeBlobModule from './NativeBlobModule';
1414

15-
1615
let BLOB_URL_PREFIX = null;
1716

1817
if (
@@ -73,13 +72,12 @@ export class URL {
7372
return `${BLOB_URL_PREFIX}${blob.data.blobId}?offset=${blob.data.offset}&size=${blob.size}`;
7473
}
7574

76-
7775
static revokeObjectURL(url: string) {
7876
// Do nothing.
7977
}
8078

8179
// $FlowFixMe[missing-local-annot]
82-
constructor(url: string, base: string | URL) {
80+
constructor(url: string, base?: string | URL) {
8381
let baseUrl = null;
8482
if (!base || validateBaseUrl(url)) {
8583
this._url = url;
@@ -109,14 +107,12 @@ export class URL {
109107
}
110108

111109
get hash(): string {
112-
const hashMatch = this._url.match(/#([^/]*)/);
113-
return hashMatch ? `#${hashMatch[1]}` : '';
110+
throw new Error('URL.hash is not implemented');
114111
}
115112

116113
get host(): string {
117114
const hostMatch = this._url.match(/^https?:\/\/(?:[^@]+@)?([^:/?#]+)/);
118115
const portMatch = this._url.match(/:(\d+)(?=[/?#]|$)/);
119-
120116
return hostMatch ? hostMatch[1] + (portMatch ? `:${portMatch[1]}` : '') : '';
121117
}
122118

@@ -139,12 +135,6 @@ export class URL {
139135
return passwordMatch ? passwordMatch[1] : '';
140136
}
141137

142-
get username(): string {
143-
144-
const usernameMatch = this._url.match(/^https?:\/\/([^:@]+)(?::[^@]*)?@/);
145-
return usernameMatch ? usernameMatch[1] : '';
146-
}
147-
148138
get pathname(): string {
149139
const pathMatch = this._url.match(/https?:\/\/[^/]+(\/[^?#]*)?/);
150140
return pathMatch ? pathMatch[1] || '/' : '/';
@@ -186,4 +176,8 @@ export class URL {
186176
return this._url + separator + instanceString;
187177
}
188178

179+
get username(): string {
180+
const usernameMatch = this._url.match(/^https?:\/\/([^:@]+)(?::[^@]*)?@/);
181+
return usernameMatch ? usernameMatch[1] : '';
182+
}
189183
}

0 commit comments

Comments
 (0)