Skip to content

Commit

Permalink
URL: Do not prepend baseUrl if the URL is not a relative URL (#26009)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jeswinsimon authored and facebook-github-bot committed Aug 13, 2019
1 parent 450e4a7 commit e104204
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Libraries/Blob/URL.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ export class URL {

constructor(url: string, base: string) {
let baseUrl = null;
if (base) {
if (!base || validateBaseUrl(url)) {
this._url = url;
if (!this._url.endsWith('/')) {
this._url += '/';
}
} else {
if (typeof base === 'string') {
baseUrl = base;
if (!validateBaseUrl(baseUrl)) {
Expand All @@ -146,11 +151,6 @@ export class URL {
url = '';
}
this._url = `${baseUrl}${url}`;
} else {
this._url = url;
if (!this._url.endsWith('/')) {
this._url += '/';
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions Libraries/Blob/__tests__/URL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ describe('URL', function() {
// expect(g.href).toBe('https://developer.mozilla.org/en-US/docs');
const h = new URL('/en-US/docs', a);
expect(h.href).toBe('https://developer.mozilla.org/en-US/docs');
const i = new URL('http://github.com', 'http://google.com');
expect(i.href).toBe('http://github.com/');
});
});

0 comments on commit e104204

Please sign in to comment.