From a99773d8d7ffcfe7145863d7c57e7c1997852b26 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 16 Apr 2025 09:45:46 -0700 Subject: [PATCH] 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 --- packages/react-native/Libraries/Blob/URL.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Blob/URL.js b/packages/react-native/Libraries/Blob/URL.js index 395e99d860a..317e1e0c26a 100644 --- a/packages/react-native/Libraries/Blob/URL.js +++ b/packages/react-native/Libraries/Blob/URL.js @@ -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 {