Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem escaping special characters to url entities #15

Open
luccasmaso opened this issue Dec 11, 2014 · 3 comments
Open

Problem escaping special characters to url entities #15

luccasmaso opened this issue Dec 11, 2014 · 3 comments

Comments

@luccasmaso
Copy link

Given the url to linkify:

https://www.site.com/someimage.jpg?var=1&option=1

The href attribute for the <a> tag has some characters (&) escaped to html entities.

https://www.site.com/someimage.jpg?var=1&amp;option=1

This way the url cannot be achieved. I suggest unescaping it back when adding the attribute do the tag.

@scottcorgan
Copy link
Owner

Want to submit a PR?

@luccasmaso
Copy link
Author

Actually I realize a simpler solution for my case, and created own directive. The regex is kind of different and more like the facebook one's

appDirectives.directive('linkify', ['$timeout', function($timeout){
  return {
    restrict: 'A',
    replace: true,
    link: function(scope, element, attrs){
      var linkify = function(text){
        if (text) {
          text = text.replace(
            /((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
            function(url){
              var full_url = url;
              if (!full_url.match('^https?:\/\/')) {
                full_url = 'http://' + full_url;
              }
              return '<a target="_blank" href="' + full_url + '">' + url + '</a>';
            }
          );
        }
        return text;
      };

      $timeout(function() {
        element.html(linkify(element.text()));
      });
    }
  };
}])

@scottcorgan
Copy link
Owner

Would this be useful in this directive? Should we use that regex?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants