From 9c9562d0fd5c426cfac5ffd5b0a1c20c60b21433 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg <maxwell@joindiaspora.com> Date: Wed, 4 Apr 2012 19:07:08 -0700 Subject: [PATCH] fix http urls with 3 slashes --- app/assets/javascripts/app/helpers/text_formatter.js | 4 ++-- spec/javascripts/app/views/post_view_spec.js | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index ccb798b454..eb9c6df9a5 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -25,7 +25,7 @@ // process links // regex copied from: https://code.google.com/p/pagedown/source/browse/Markdown.Converter.js#1198 (and slightly expanded) - var linkRegex = /(\[.*\]:\s)?(<|\()((https?|ftp):[^'">\s]+)(>|\))/gi; + var linkRegex = /(\[.*\]:\s)?(<|\()((https?|ftp):\/\/[^\/'">\s][^'">\s]+)(>|\))/gi; text = text.replace(linkRegex, function() { var unicodeUrl = arguments[3]; var addr = parse_url(unicodeUrl); @@ -34,7 +34,7 @@ ( (addr.scheme.toLowerCase()=="mailto") ? ':' : '://')) + (!addr.user ? '' : addr.user + (!addr.pass ? '' : ':'+addr.pass) + '@') + - punycode.toASCII(addr.host) + + punycode.toASCII(addr.host) + (!addr.port ? '' : ':' + addr.port) + (!addr.path ? '' : addr.path) + (!addr.query ? '' : '?' + addr.query) + diff --git a/spec/javascripts/app/views/post_view_spec.js b/spec/javascripts/app/views/post_view_spec.js index 2bdf7af71e..c0d299df52 100644 --- a/spec/javascripts/app/views/post_view_spec.js +++ b/spec/javascripts/app/views/post_view_spec.js @@ -69,5 +69,12 @@ describe("app.views.Post", function(){ expect($(view.el).html()).toContain(specialLink); expect($(view.el).html()).toContain(normalLink); }); + it("works when three slashes are present in the url", function(){ + var badURL = "http:///scholar.google.com/citations?view_op=top_venues" + this.statusMessage.set({text : badURL}); + var view = new app.views.StreamPost({model: this.statusMessage}).render(); + + }) + }); }); -- GitLab