mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Properly join url and path with / separator in Meteor.absoluteUrl.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user