File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -40,10 +40,9 @@ function absolute(path, $) {
40
40
41
41
if ( ~ src . indexOf ( '://' ) ) {
42
42
return ;
43
- } else if ( src [ 0 ] == '/' ) {
44
- src = remote + src ;
45
43
} else {
46
- src = remote + '/' + parts . pathname . replace ( / ^ \/ / , '' ) + '/' + src
44
+ var current = url . resolve ( remote , parts . pathname ) ;
45
+ src = url . resolve ( current , src ) ;
47
46
}
48
47
49
48
$el . attr ( key , src ) ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ var isArray = Array.isArray;
10
10
var subs = require ( 'subs' ) ;
11
11
var xray = require ( '..' ) ;
12
12
var fs = require ( 'fs' ) ;
13
+ var cheerio = require ( 'cheerio' ) ;
14
+ var absolute = require ( '../lib/utils/absolute-urls' ) ;
13
15
14
16
/**
15
17
* Tests
@@ -252,6 +254,26 @@ describe('x-ray', function() {
252
254
done ( ) ;
253
255
} )
254
256
} )
257
+
258
+ describe ( 'absolute URLs' , function ( ) {
259
+ var $el ;
260
+ var path = 'http://example.com/foo.html' ;
261
+
262
+ it ( 'should not convert URL' , function ( ) {
263
+ $el = cheerio . load ( '<a href="http://example.com/bar.html"></a>' ) ;
264
+ assert . equal ( '<a href="http://example.com/bar.html"></a>' , absolute ( path , $el ) . html ( ) ) ;
265
+ } ) ;
266
+
267
+ it ( 'should convert absolute URL' , function ( ) {
268
+ $el = cheerio . load ( '<a href="/bar.html"></a>' ) ;
269
+ assert . equal ( '<a href="http://example.com/bar.html"></a>' , absolute ( path , $el ) . html ( ) ) ;
270
+ } ) ;
271
+
272
+ it ( 'should convert relative URL' , function ( ) {
273
+ $el = cheerio . load ( '<a href="bar.html"></a>' ) ;
274
+ assert . equal ( '<a href="http://example.com/bar.html"></a>' , absolute ( path , $el ) . html ( ) ) ;
275
+ } ) ;
276
+ } ) ;
255
277
} )
256
278
257
279
/**
You can’t perform that action at this time.
0 commit comments