Skip to content

Commit e104204

Browse files
jeswinsimonfacebook-github-bot
authored andcommitted
URL: Do not prepend baseUrl if the URL is not a relative URL (#26009)
Summary: Fix for bug #26006 URL with base is always used, even when absolute URL is provided ## Changelog [Javascript] [Fixed] - `URL`: Base url value is ignored when the input url is not a relative url. Pull Request resolved: #26009 Test Plan: `new URL('http://github.com', 'http://google.com')` now returns `http://github.com/` Added a test case to `URL-test.js` to verify the same. Differential Revision: D16781921 Pulled By: cpojer fbshipit-source-id: 038aca3610e34f513f603e8993f9a925b7d28626
1 parent 450e4a7 commit e104204

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Libraries/Blob/URL.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,12 @@ export class URL {
130130

131131
constructor(url: string, base: string) {
132132
let baseUrl = null;
133-
if (base) {
133+
if (!base || validateBaseUrl(url)) {
134+
this._url = url;
135+
if (!this._url.endsWith('/')) {
136+
this._url += '/';
137+
}
138+
} else {
134139
if (typeof base === 'string') {
135140
baseUrl = base;
136141
if (!validateBaseUrl(baseUrl)) {
@@ -146,11 +151,6 @@ export class URL {
146151
url = '';
147152
}
148153
this._url = `${baseUrl}${url}`;
149-
} else {
150-
this._url = url;
151-
if (!this._url.endsWith('/')) {
152-
this._url += '/';
153-
}
154154
}
155155
}
156156

Libraries/Blob/__tests__/URL-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ describe('URL', function() {
3131
// expect(g.href).toBe('https://developer.mozilla.org/en-US/docs');
3232
const h = new URL('/en-US/docs', a);
3333
expect(h.href).toBe('https://developer.mozilla.org/en-US/docs');
34+
const i = new URL('http://github.com', 'http://google.com');
35+
expect(i.href).toBe('http://github.com/');
3436
});
3537
});

0 commit comments

Comments
 (0)