File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ const Cache = require('./cache');
9
9
const cache = new Cache ( ) ;
10
10
11
11
function urlForHelper ( path = '/' , options ) {
12
+ if ( / ^ ( # | \/ \/ | h t t p ( s ) ? : ) / . test ( path ) ) return path ;
13
+
12
14
const { config } = this ;
13
15
14
16
options = Object . assign ( {
@@ -28,8 +30,6 @@ function urlForHelper(path = '/', options) {
28
30
29
31
// cacheId is designed to works across different hexo.config & options
30
32
return cache . apply ( `${ config . url } -${ root } -${ prettyUrlsOptions . trailing_index } -${ prettyUrlsOptions . trailing_html } -${ path } ` , ( ) => {
31
- if ( / ^ ( # | \/ \/ | h t t p ( s ) ? : ) / . test ( path ) ) return path ;
32
-
33
33
const sitehost = parse ( config . url ) . hostname || config . url ;
34
34
const data = new URL ( path , `http://${ sitehost } ` ) ;
35
35
Original file line number Diff line number Diff line change @@ -128,6 +128,20 @@ describe('url_for', () => {
128
128
} ) ;
129
129
} ) ;
130
130
131
+ it ( 'absolute url - should not be processed by relative_url' , ( ) => {
132
+ ctx . config . relative_link = true ;
133
+ [
134
+ 'https://hexo.io/' ,
135
+ '//google.com/' ,
136
+ 'https://hexo.io/docs/index.html' ,
137
+ 'http://example.com/foo/bar/' ,
138
+ 'https://example.com/foo/bar/'
139
+ ] . forEach ( url => {
140
+ urlFor ( url ) . should . eql ( url ) ;
141
+ } ) ;
142
+ ctx . config . relative_link = false ;
143
+ } ) ;
144
+
131
145
it ( 'only hash' , ( ) => {
132
146
urlFor ( '#test' ) . should . eql ( '#test' ) ;
133
147
} ) ;
You can’t perform that action at this time.
0 commit comments