diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index a3733b629..a6fc1c391 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -42,6 +42,7 @@ }); md.use(inlinePlugin, 'link_new_window_and_punycode', 'link_open', function (tokens, idx) { + tokens[idx].href = tokens[idx].href.replace(/^www\./, "http://www."); tokens[idx].href = punycodeURL(tokens[idx].href); tokens[idx].target = "_blank"; }); diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index 0343dc4ed..cbdfbe6ac 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -116,6 +116,11 @@ describe("app.helpers.textFormatter", function(){ expect(this.formatter('')).toContain('_blank'); }); + it("adds a missing http://", function() { + expect(this.formatter('[test](www.google.com)')).toContain('href="http://www.google.com"'); + expect(this.formatter('[test](http://www.google.com)')).toContain('href="http://www.google.com"'); + }); + it("respects code blocks", function() { var content = '``'; var wrapper = $('
').html(this.formatter(content));