mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix URL parsing to respect node/chromium convention (#50757)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50757 We received [this issue](https://github.com/facebook/react-native/issues/50747) in OSS where the URL parsing logic does not respect node/chromium specs. This can cause issue in usercode. This change fixes it ## Changelog: [General][Fixed] - make sure that URLs are parsed following the node specs Reviewed By: huntie Differential Revision: D73101813 fbshipit-source-id: 36f1d23b3ad7882c16524843621d9ebbcc09b95d
This commit is contained in:
committed by
React Native Bot
parent
22a4e060d5
commit
a99773d8d7
+13
-1
@@ -81,7 +81,19 @@ export class URL {
|
||||
let baseUrl = null;
|
||||
if (!base || validateBaseUrl(url)) {
|
||||
this._url = url;
|
||||
if (!this._url.endsWith('/')) {
|
||||
if (this._url.includes('#')) {
|
||||
const split = this._url.split('#');
|
||||
const beforeHash = split[0];
|
||||
const website = beforeHash.split('://')[1];
|
||||
if (!website.includes('/')) {
|
||||
this._url = split.join('/#');
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!this._url.endsWith('/') &&
|
||||
!(this._url.includes('?') || this._url.includes('#'))
|
||||
) {
|
||||
this._url += '/';
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user