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');