From 3298373a7fd57b6f7f23cb5a36bce0806476b07d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Mon, 9 Mar 2015 01:29:16 +0100 Subject: [PATCH] Add missing http:// to urls --- app/assets/javascripts/app/helpers/text_formatter.js | 1 + spec/javascripts/app/helpers/text_formatter_spec.js | 5 +++++ 2 files changed, 6 insertions(+) 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));