Skip to content
Permalink
Browse files

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
  • Loading branch information...
jeswinsimon authored and facebook-github-bot committed Aug 13, 2019
1 parent 450e4a7 commit e104204ae083d31e0b9967373ce79f2f1ca8fbb6
Showing with 8 additions and 6 deletions.
  1. +6 −6 Libraries/Blob/URL.js
  2. +2 −0 Libraries/Blob/__tests__/URL-test.js
@@ -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)) {
@@ -146,11 +151,6 @@ export class URL {
url = '';
}
this._url = `${baseUrl}${url}`;
} else {
this._url = url;
if (!this._url.endsWith('/')) {
this._url += '/';
}
}
}

@@ -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.
You can’t perform that action at this time.