react-native-autolink
react-native-autolink copied to clipboard
Url parsing
if text is
aaa:google.com
and
url={true}
then entire text is linkified ... it really should be aaa: as string and google.com as link (tldMatches picks up .com correctly but fails to split the preceded text)
URL matching is handled under the hood by Autolinker.js. From what I can tell, this is a side effect of matching URL schemes, so disabling schemeMatches fixes the issue, though that may not be optimal depending on your use case. You can also use a custom matcher with a custom regex for more control.
I'll do a bit of digging to see if there's anything that can be done here.
Related issue: https://github.com/gregjacobs/Autolinker.js/issues/352
Yeah, tldMatches false fixes it but that's undesirable. SchemeMatches shouldn't have impact on this, will test. Proper fix would be in AutoLinker, thx for raising issue there :+1:
Hi @Kelt @joshswan any update on this issue
Unfortunately it doesn't look like there's been any progress on the Autolinker.js side. I'm exploring a few options on my end but basically everything I've come up with is going to be a breaking change.
My best suggestion for now is to disable the default URL parsing and implement a custom matcher that better suits your needs. The more restrictive regex /(https?:\/\/|www\.)[-a-zA-Z0-9@:%._\+~#=]{1,256}\.(xn--)?[a-z0-9-]{2,20}\b([-a-zA-Z0-9@:%_\+\[\],.~#?&\/=]*[-a-zA-Z0-9@:%_\+\]~#?&\/=])*/i
handles this case correctly at the expense of requiring an http(s) or www at the start of a link.