gregjacobs / Autolinker.js

Utility to Automatically Link URLs, Email Addresses, Phone Numbers, Twitter handles, and Hashtags in a given block of text/HTML
MIT License
1.48k stars 238 forks source link

Does not cut links that end with non-latin symbols based on domain correctly #278

Open kibertoad opened 5 years ago

kibertoad commented 5 years ago

Once upon a time there was this issue reported in remarkable: https://github.com/jonschlinkert/remarkable/issues/51

Fix worked just fine up to Autolinker version 1.4.1. On 1.4.2+ the non-latin part was once again included together with the latin domain in parsed url. Most likely this is related to https://github.com/gregjacobs/Autolinker.js/pull/201 being merged.

My question is this: would you consider that a regression or breaking change from autolinker side? Or previous behaviour was wrong and current one is preferable?

Commit with fix for ease of reference (illustrates what autolinker API is used, and what is expected outcome): https://github.com/jonschlinkert/remarkable/commit/719d4c18888d47458e0f997a832909c3f2ab348f

Newest version generates this: -<p><a href="http://www.example.org版权所有">www.example.org版权所有</a></p>

gregjacobs commented 5 years ago

Hey @kibertoad, interesting issue. Seems like a regression to me that it includes the non-latin symbols, and it looks like it doesn't link it at all if not prefixed by http or www. I see the following behavior at the moment:

link('http://www.example.org版权所有')  // <a href="http://www.example.org版权所有">example.org版权所有</a>
link('www.example.org版权所有')         // <a href="http://www.example.org版权所有">example.org版权所有</a>
link('example.org版权所有')             // example.org版权所有 (no link generated)

Do you think the correct behavior would be the following?

link('http://www.example.org版权所有')  // <a href="http://www.example.org">example.org</a>版权所有
link('www.example.org版权所有')         // <a href="http://www.example.org">example.org</a>版权所有
link('example.org版权所有')             // <a href="http://www.example.org">example.org</a>版权所有
kibertoad commented 5 years ago

Yes, that looks correct. Thank you for the quick response!

TrySound commented 5 years ago

Hi @gregjacobs. Do you have some time to take a look at this issue?

TrySound commented 5 years ago

I see in this test that such behaviour is expected. https://github.com/gregjacobs/Autolinker.js/blob/master/tests/autolinker-url.spec.ts#L201