Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Bizzare behavior when Linky meets double quotes("") and (>) in url #5946

Closed
@sunderls

Description

@sunderls

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=&#34;ddddd&gt;test</a> so 

after sanitizing, it becomes

<a href="http://www.google.co.jp/search/?q=">test&#34;&gt;http://www.google.co.jp/search/?q=&#34;ddddd&gt;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 &quot;,

html.push(url.replace(/"/g,'&quot;');

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions