From a8a97016b7c387a4944f9fdff30152f40d0dfd82 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Sat, 12 May 2018 11:22:20 -0400 Subject: [PATCH] Properly join url and path with / separator in Meteor.absoluteUrl. --- packages/meteor/url_common.js | 12 +++++++++--- packages/meteor/url_tests.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/meteor/url_common.js b/packages/meteor/url_common.js index 4d3c5d454b..3259499e14 100644 --- a/packages/meteor/url_common.js +++ b/packages/meteor/url_common.js @@ -23,11 +23,17 @@ Meteor.absoluteUrl = function (path, options) { if (!/^http[s]?:\/\//i.test(url)) // url starts with 'http://' or 'https://' url = 'http://' + url; // we will later fix to https if options.secure is set - if (!/\/$/.test(url)) // url ends with '/' - url += '/'; + if (! url.endsWith("/")) { + url += "/"; + } - if (path) + if (path) { + // join url and path with a / separator + while (path.startsWith("/")) { + path = path.slice(1); + } url += path; + } // turn http to https if secure option is set, and we're not talking // to localhost. diff --git a/packages/meteor/url_tests.js b/packages/meteor/url_tests.js index ad686ceb16..365928e1e1 100644 --- a/packages/meteor/url_tests.js +++ b/packages/meteor/url_tests.js @@ -11,7 +11,7 @@ Tinytest.add("absolute-url - basics", function(test) { test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'asdf.com/'}), 'http://asdf.com/foo'); test.equal(Meteor.absoluteUrl('/foo', {rootUrl: prefix + 'asdf.com'}), - 'http://asdf.com//foo'); + 'http://asdf.com/foo'); test.equal(Meteor.absoluteUrl('#foo', {rootUrl: prefix + 'asdf.com'}), 'http://asdf.com/#foo');