diff --git a/lib/plugins/helper/url_for.js b/lib/plugins/helper/url_for.js index 0d9e2ce853..7a9aba73cd 100644 --- a/lib/plugins/helper/url_for.js +++ b/lib/plugins/helper/url_for.js @@ -26,13 +26,9 @@ function urlForHelper(path, options){ } // Prepend root path - if(path === '/') { - return root; - } else if (path[0] !== '/'){ - return root + path; - } + path = root + path; - return path; + return path.replace(/\/{2,}/g, '/'); } module.exports = urlForHelper; diff --git a/test/scripts/helpers/url_for.js b/test/scripts/helpers/url_for.js index 379b90dc16..de4fe79649 100644 --- a/test/scripts/helpers/url_for.js +++ b/test/scripts/helpers/url_for.js @@ -14,10 +14,12 @@ describe('url_for', function(){ ctx.config.root = '/'; urlFor('index.html').should.eql('/index.html'); urlFor('/').should.eql('/'); + urlFor('/index.html').should.eql('/index.html'); ctx.config.root = '/blog/'; urlFor('index.html').should.eql('/blog/index.html'); urlFor('/').should.eql('/blog/'); + urlFor('/index.html').should.eql('/blog/index.html'); }); it('internal url (relative on)', function(){