Skip to content

fix: app crash on open non protocol link#96

Open
alekseyFilonenkoDev wants to merge 1 commit intoobipawan:masterfrom
alekseyFilonenkoDev:fix/non-protocol-url-crash
Open

fix: app crash on open non protocol link#96
alekseyFilonenkoDev wants to merge 1 commit intoobipawan:masterfrom
alekseyFilonenkoDev:fix/non-protocol-url-crash

Conversation

@alekseyFilonenkoDev
Copy link
Copy Markdown

@alekseyFilonenkoDev alekseyFilonenkoDev commented Apr 16, 2026

Description

Fixes the TypeError: Cannot read property 'toLowerCase' that occurs when open //example.com link.

Changes

  • added optional chaining for protocol.toLowerCase() and nullish coalescing to empty string
  • catch added to Linking.openURL
    • onLinkError added to props for passing error that could happen on Linking.openURL

Problem

Pressing on //example.com link leads to App crash right now. That’s because mdurl.parse **returns protocol as null for url like this (even though TS shows Url.protocol: string).

After TypeError fix Linking.openURL fails, so it also should be addressed.

Solution

While [//example.com](https://example.com/) invalid for RN, it’s actually valid link for web browsers, so it shouldn’t be prohibited.

So make protocol empty string (which it is for given link), and handle openURL error. Also add link error handler, so lib users could get actual error and handle it.

Testing

  • ✅ Tested with React Native 0.82.1 with new architecture enabled
  • ✅ Backward compatible with older React Native versions
  • ✅ No breaking changes to existing API
  • ✅ New unit tests added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant