diff --git a/packages/react-native/Libraries/Blob/URL.js b/packages/react-native/Libraries/Blob/URL.js index f4f879a51214..236e3ce5a666 100644 --- a/packages/react-native/Libraries/Blob/URL.js +++ b/packages/react-native/Libraries/Blob/URL.js @@ -85,7 +85,7 @@ export class URL { const split = this._url.split('#'); const beforeHash = split[0]; const website = beforeHash.split('://')[1]; - if (!website.includes('/')) { + if (website != null && !website.includes('/')) { this._url = split.join('/#'); } } diff --git a/packages/react-native/Libraries/Blob/__tests__/URL-test.js b/packages/react-native/Libraries/Blob/__tests__/URL-test.js index 72467dc08ebb..cc597a1e780a 100644 --- a/packages/react-native/Libraries/Blob/__tests__/URL-test.js +++ b/packages/react-native/Libraries/Blob/__tests__/URL-test.js @@ -168,4 +168,9 @@ describe('URL', function () { 'https://example.com/path/to/resource', ); }); + + it('should handle URLs with hash but no protocol separator', () => { + // URL with hash but no "://" should not crash + expect(() => new URL('mailto:user@example.com#section')).not.toThrow(); + }); });