react-native-autolink icon indicating copy to clipboard operation
react-native-autolink copied to clipboard

Url parsing

Open Kelt opened this issue 3 years ago • 4 comments

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)

Kelt avatar Jun 29 '21 13:06 Kelt

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

joshswan avatar Jun 29 '21 17:06 joshswan

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:

Kelt avatar Jun 29 '21 17:06 Kelt

Hi @Kelt @joshswan any update on this issue

saiaryan avatar Nov 27 '21 11:11 saiaryan

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.

joshswan avatar Nov 29 '21 18:11 joshswan