File tree 3 files changed +74
-2
lines changed
3 files changed +74
-2
lines changed Original file line number Diff line number Diff line change @@ -1426,11 +1426,18 @@ function resolveUrl(base, href) {
1426
1426
}
1427
1427
}
1428
1428
base = baseUrls [ ' ' + base ] ;
1429
+ var relativeBase = base . indexOf ( ':' ) === - 1 ;
1429
1430
1430
1431
if ( href . slice ( 0 , 2 ) === '//' ) {
1431
- return base . replace ( / : [ \s \S ] * / , ':' ) + href ;
1432
+ if ( relativeBase ) {
1433
+ return href ;
1434
+ }
1435
+ return base . replace ( / ^ ( [ ^ : ] + : ) [ \s \S ] * $ / , '$1' ) + href ;
1432
1436
} else if ( href . charAt ( 0 ) === '/' ) {
1433
- return base . replace ( / ( : \/ * [ ^ / ] * ) [ \s \S ] * / , '$1' ) + href ;
1437
+ if ( relativeBase ) {
1438
+ return href ;
1439
+ }
1440
+ return base . replace ( / ^ ( [ ^ : ] + : \/ * [ ^ / ] * ) [ \s \S ] * $ / , '$1' ) + href ;
1434
1441
} else {
1435
1442
return base + href ;
1436
1443
}
Original file line number Diff line number Diff line change
1
+ < h1 id ="absolutization-of-rfc-3986-uris "> Absolutization of RFC 3986 URIs</ h1 >
2
+
3
+ < h2 id ="absolute-uri "> Absolute URI</ h2 >
4
+
5
+ < p > < a href ="http://example.com/ "> < img src ="http://example.com/logo " alt ="section 4.3 "> </ a > </ p >
6
+
7
+ < h2 id ="network-path-reference "> Network-path reference</ h2 >
8
+
9
+ < p > < a href ="//example.com/ "> < img src ="//example.com/logo " alt ="section 4.2 "> </ a > </ p >
10
+
11
+ < h2 id ="absolute-path "> Absolute path</ h2 >
12
+
13
+ < p > < a href ="/path/to/content "> < img src ="/path/to/img " alt ="section 4.2 "> </ a > </ p >
14
+
15
+ < h2 id ="relative-path "> Relative path</ h2 >
16
+
17
+ < p > < a href ="/base/content "> < img src ="/base/img " alt ="section 4.2 "> </ a > </ p >
18
+
19
+ < h2 id ="dot-relative-path "> Dot-relative path</ h2 >
20
+
21
+ < p > < a href ="/base/./content "> < img src ="/base/./img " alt ="section 3.3 "> </ a > </ p >
22
+
23
+ < p > < a href ="/base/../content "> < img src ="/base/../img " alt ="section 3.3 "> </ a > </ p >
24
+
25
+ < h2 id ="same-document-query "> Same-document query</ h2 >
26
+
27
+ < p > < a href ="? "> < img src ="?type=image " alt ="section 4.4 "> </ a > </ p >
28
+
29
+ < h2 id ="same-document-fragment "> Same-document fragment</ h2 >
30
+
31
+ < p > < a href ="# "> < img src ="#img " alt ="section 4.4 "> </ a > </ p >
32
+
33
+ < h2 id ="empty "> Empty</ h2 >
34
+
35
+ < p > < a href =""> section 4.2</ a > </ p >
Original file line number Diff line number Diff line change
1
+ ---
2
+ baseUrl : " /base/"
3
+ ---
4
+ # Absolutization of RFC 3986 URIs
5
+
6
+ ## Absolute URI
7
+ [ ![ section 4.3] ( http://example.com/logo )] ( http://example.com/ )
8
+
9
+ ## Network-path reference
10
+ [ ![ section 4.2] ( //example.com/logo )] ( //example.com/ )
11
+
12
+ ## Absolute path
13
+ [ ![ section 4.2] ( /path/to/img )] ( /path/to/content )
14
+
15
+ ## Relative path
16
+ [ ![ section 4.2] ( img )] ( content )
17
+
18
+ ## Dot-relative path
19
+ [ ![ section 3.3] ( ./img )] ( ./content )
20
+
21
+ [ ![ section 3.3] ( ../img )] ( ../content )
22
+
23
+ ## Same-document query
24
+ [ ![ section 4.4] ( ?type=image )] ( ? )
25
+
26
+ ## Same-document fragment
27
+ [ ![ section 4.4] ( #img )] ( # )
28
+
29
+ ## Empty
30
+ [ section 4.2] ( )
You can’t perform that action at this time.
0 commit comments