Skip to content

Commit ef6e15d

Browse files
committed
url_for helper: Don't prepend root if url is started with #
Fix #1708
1 parent c80de2d commit ef6e15d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/plugins/helper/url_for.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ var _ = require('lodash');
66
function urlForHelper(path, options) {
77
path = path || '/';
88

9+
if (path[0] === '#' || path.substring(0, 2) === '//') {
10+
return path;
11+
}
12+
913
var config = this.config;
1014
var root = config.root;
1115
var data = url.parse(path);
@@ -15,7 +19,7 @@ function urlForHelper(path, options) {
1519
}, options);
1620

1721
// Exit if this is an external path
18-
if (data.protocol || path.substring(0, 2) === '//') {
22+
if (data.protocol) {
1923
return path;
2024
}
2125

test/scripts/helpers/url_for.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@ describe('url_for', function() {
5252
urlFor(url).should.eql(url);
5353
});
5454
});
55+
56+
it('only hash', function() {
57+
urlFor('#test').should.eql('#test');
58+
});
5559
});

0 commit comments

Comments
 (0)