Skip to content
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

πŸš€ Enhance Pull-to-Refresh Functionality with Native Sync and Improvements πŸ”„ #48632

Closed
wants to merge 11 commits into from
54 changes: 34 additions & 20 deletions packages/react-native/Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* @flow
*/

import type Blob from './Blob';

Check warning on line 11 in packages/react-native/Libraries/Blob/URL.js

View workflow job for this annotation

GitHub Actions / test_js (20)

Requires should be sorted alphabetically

Check warning on line 11 in packages/react-native/Libraries/Blob/URL.js

View workflow job for this annotation

GitHub Actions / test_js (18)

Requires should be sorted alphabetically

import NativeBlobModule from './NativeBlobModule';

let BLOB_URL_PREFIX = null;
Expand Down Expand Up @@ -51,8 +50,7 @@
* </resources>
* ```
*/

export {URLSearchParams} from './URLSearchParams';
export { URLSearchParams } from './URLSearchParams';

function validateBaseUrl(url: string) {
// from this MIT-licensed gist: https://gist.github.com/dperini/729294
Expand All @@ -64,6 +62,7 @@
export class URL {
_url: string;
_searchParamsInstance: ?URLSearchParams = null;
_parsedUrl: ?URL = null;

static createObjectURL(blob: Blob): string {
if (BLOB_URL_PREFIX === null) {
Expand Down Expand Up @@ -106,49 +105,66 @@
}
}

_parseUrlIfNeeded() {
if (this._parsedUrl == null) {
this._parsedUrl = new (globalThis || window).URL(this._url);
}
}

get hash(): string {
throw new Error('URL.hash is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.hash;
}

get host(): string {
throw new Error('URL.host is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.host;
}

get hostname(): string {
throw new Error('URL.hostname is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.hostname;
}

get href(): string {
this._parseUrlIfNeeded();
return this.toString();
}

get origin(): string {
throw new Error('URL.origin is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.origin;
}

get password(): string {
throw new Error('URL.password is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.password;
}

get pathname(): string {
throw new Error('URL.pathname not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.pathname;
}

get port(): string {
throw new Error('URL.port is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.port;
}

get protocol(): string {
throw new Error('URL.protocol is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.protocol;
}

get search(): string {
throw new Error('URL.search is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.search;
}

get searchParams(): URLSearchParams {
this._parseUrlIfNeeded();
if (this._searchParamsInstance == null) {
this._searchParamsInstance = new URLSearchParams();
this._searchParamsInstance = new URLSearchParams(this._parsedUrl.search);
}
return this._searchParamsInstance;
}
Expand All @@ -158,16 +174,14 @@
}

toString(): string {
if (this._searchParamsInstance === null) {
return this._url;
}
// $FlowFixMe[incompatible-use]
const instanceString = this._searchParamsInstance.toString();
this._parseUrlIfNeeded();
const instanceString = this._searchParamsInstance ? this._searchParamsInstance.toString() : '';
const separator = this._url.indexOf('?') > -1 ? '&' : '?';
return this._url + separator + instanceString;
return this._url + (instanceString ? separator + instanceString : '');
}

get username(): string {
throw new Error('URL.username is not implemented');
this._parseUrlIfNeeded();
return this._parsedUrl.username;
}
}
16 changes: 16 additions & 0 deletions packages/react-native/Libraries/Blob/__tests__/URL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,20 @@ describe('URL', function () {
const k = new URL('en-US/docs', 'https://developer.mozilla.org');
expect(k.href).toBe('https://developer.mozilla.org/en-US/docs');
});

it('should implement host, hostname, username, and password accessors correctly', () => {
const url = new URL('https://username:[email protected]:8080/en-US/docs?query=test#fragment');

// Test host
expect(url.host).toBe('developer.mozilla.org:8080');

// Test hostname
expect(url.hostname).toBe('developer.mozilla.org');

// Test username
expect(url.username).toBe('username');

// Test password
expect(url.password).toBe('password');
});
});
Loading