@@ -41,38 +41,25 @@ import window from 'global/window';
41
41
* An object of url details
42
42
*/
43
43
export const parseUrl = function ( url ) {
44
+ // This entire method can be replace with URL once we are able to drop IE11
45
+
44
46
const props = [ 'protocol' , 'hostname' , 'port' , 'pathname' , 'search' , 'hash' , 'host' ] ;
45
47
46
48
// add the url to an anchor and let the browser parse the URL
47
- let a = document . createElement ( 'a' ) ;
49
+ const a = document . createElement ( 'a' ) ;
48
50
49
51
a . href = url ;
50
52
51
- // IE8 (and 9?) Fix
52
- // ie8 doesn't parse the URL correctly until the anchor is actually
53
- // added to the body, and an innerHTML is needed to trigger the parsing
54
- const addToBody = ( a . host === '' && a . protocol !== 'file:' ) ;
55
- let div ;
56
-
57
- if ( addToBody ) {
58
- div = document . createElement ( 'div' ) ;
59
- div . innerHTML = `<a href="${ url } "></a>` ;
60
- a = div . firstChild ;
61
- // prevent the div from affecting layout
62
- div . setAttribute ( 'style' , 'display:none; position:absolute;' ) ;
63
- document . body . appendChild ( div ) ;
64
- }
65
-
66
53
// Copy the specific URL properties to a new object
67
- // This is also needed for IE8 because the anchor loses its
54
+ // This is also needed for IE because the anchor loses its
68
55
// properties when it's removed from the dom
69
56
const details = { } ;
70
57
71
58
for ( let i = 0 ; i < props . length ; i ++ ) {
72
59
details [ props [ i ] ] = a [ props [ i ] ] ;
73
60
}
74
61
75
- // IE9 adds the port to the host property unlike everyone else. If
62
+ // IE adds the port to the host property unlike everyone else. If
76
63
// a port identifier is added for standard ports, strip it.
77
64
if ( details . protocol === 'http:' ) {
78
65
details . host = details . host . replace ( / : 8 0 $ / , '' ) ;
@@ -86,8 +73,9 @@ export const parseUrl = function(url) {
86
73
details . protocol = window . location . protocol ;
87
74
}
88
75
89
- if ( addToBody ) {
90
- document . body . removeChild ( div ) ;
76
+ /* istanbul ignore if */
77
+ if ( ! details . host ) {
78
+ details . host = window . location . host ;
91
79
}
92
80
93
81
return details ;
0 commit comments