Bizzare behavior when Linky meets double quotes("") and (>) in url #5946
Description
Hei, guys,
we are building a project using Angular, but found that filter linky
have bizzare behavior when the url has double quotes and >
steps to reproduce
for this piece of raw text
https://www.google.co.jp/search?q="ddddd>test so
"linky" will generate something like this
<a href="https://www.google.co.jp/search?q=">test">https://www.google.co.jp/search?q="ddddd>test</a> so
looking at source code
the linky.js use this function to generate <a>
element,
function addLink(url, text) {
html.push('<a ');
if (angular.isDefined(target)) {
html.push('target="');
html.push(target);
html.push('" ');
}
html.push('href="');
html.push(url);
html.push('">');
addText(text);
html.push('</a>');
}
the thing is , new <a>
element's attribute is surrounded by double quote "
, and if the url
detected from regexp also has double quote, problems occur. The html generated before sanitizing is
<a href="http://www.google.co.jp/search/?q="ddddd>test">http://www.google.co.jp/search/?q="ddddd>test</a> so
after sanitizing, it becomes
<a href="http://www.google.co.jp/search/?q=">test">http://www.google.co.jp/search/?q="ddddd>test</a> so
as you can see, extra "test" comes and the link url is sliced.
if there is only double quote "
and no >
, the link text is ok but url is still not full.
Suggestion
Although it is not often to have "
or >
to be seen in a url , but since the Regexp used to detect link allows both of them, so I think maybe it's best to make look good.
maybe one way is to change "
to "
,
html.push(url.replace(/"/g,'"');