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

Link not fully created when containing { or } #120

Closed asiminiceanu closed 8 years ago

asiminiceanu commented 9 years ago

Hello,

I have the following link that it is not parsed correctly using 0.18.1:

https://aaa.com?bbb={ccc}

It results in:

<a href="https://aaa.com?bbb=" target="_blank">https://aaa.com?bbb=</a>{ccc}

My call to the link method is:

text = Autolinker.link(
                        message.text, 
                        {
                            twitter: false,
                            replaceFn : function(autolinker, match) {
                                var tag = autolinker.getTagBuilder().build(match);  
                                tag.setInnerHtml(match.getMatchedText());
                                return tag; 
                            }
                        }
                   );
gregjacobs commented 8 years ago

Hey, so { and } aren't actually valid in a url. They need to be %-encoded into https://aaa.com?bbb=%7Bccc%7D

Unfortunately Autolinker can't auto-link these without violating the RFC. See the first answer here for an explanation: http://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid