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

Bad links from nested quotes inside <a href> #190

Closed jpeterson-isdc closed 7 years ago

jpeterson-isdc commented 7 years ago

Autolinker seems to be struggling with the following example:

        var autolinker = require('autolinker');
        var options = {
            urls: true,
            newWindow: false,
        };
        var input = '<a href="http://google.com" style="font-family: "Times New Roman";">Google</a>';
        var output = autolinker.link(input, options);
        console.log(output);

The result is

                   <a href="<a href="http://google.com">google.com</a>" style="font-family: "Times New Roman";">Google</a>

This sample html came from a workflow where a user copied html which contained a link from Outlook and pasted it into our html editor. That html was then processed with Autolinker.

If I replace the double quotes around the value of the style attribute then Autolinker is able to handle the html, so I think Autolinker is having problems because of the nested double quotes.

Is there a way to work around this problem with the current version of Autolinker?

jpeterson-isdc commented 7 years ago

I think this can be closed as I now see that the html coming from Outlook is not valid. The inner double quotes should be escaped.

olafleur commented 7 years ago

Ok. Don't hesitate if you see other use cases where Autolinker would be wrong. :)