Skip to content

Commit 963a84c

Browse files
committed
IE7 returns an empty string for regexp submatches while all other browsers return undefined. Modified the parseUrl() function to normalize all non-matches to an empty string and replaced all strict checks for undefined to strict checks for an empty string.
1 parent a337e6d commit 963a84c

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

js/jquery.mobile.navigation.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,27 @@
5353
matches = path.urlParseRE.exec( url ),
5454
results;
5555
if ( matches ) {
56+
// Create an object that allows the caller to access the sub-matches
57+
// by name. Note that IE returns an empty string instead of undefined,
58+
// like all other browsers do, so we normalize everything so its consistent
59+
// no matter what browser we're running on.
5660
results = {
57-
href: matches[0],
58-
hrefNoHash: matches[1],
59-
hrefNoSearch: matches[2],
60-
domain: matches[3],
61-
protocol: matches[4],
62-
authority: matches[5],
63-
username: matches[7],
64-
password: matches[8],
65-
host: matches[9],
66-
hostname: matches[10],
67-
port: matches[11],
68-
pathname: matches[12],
69-
directory: matches[13],
70-
filename: matches[14],
71-
search: matches[15],
72-
hash: matches[16]
61+
href: matches[0] || "",
62+
hrefNoHash: matches[1] || "",
63+
hrefNoSearch: matches[2] || "",
64+
domain: matches[3] || "",
65+
protocol: matches[4] || "",
66+
authority: matches[5] || "",
67+
username: matches[7] || "",
68+
password: matches[8] || "",
69+
host: matches[9] || "",
70+
hostname: matches[10] || "",
71+
port: matches[11] || "",
72+
pathname: matches[12] || "",
73+
directory: matches[13] || "",
74+
filename: matches[14] || "",
75+
search: matches[15] || "",
76+
hash: matches[16] || ""
7377
};
7478
}
7579
return results || {};
@@ -114,12 +118,12 @@
114118
//Returns true for any relative variant.
115119
isRelativeUrl: function( url ) {
116120
// All relative Url variants have one thing in common, no protocol.
117-
return path.parseUrl( url ).protocol === undefined;
121+
return path.parseUrl( url ).protocol === "";
118122
},
119123

120124
//Returns true for an absolute url.
121125
isAbsoluteUrl: function( url ) {
122-
return path.parseUrl( url ).protocol !== undefined;
126+
return path.parseUrl( url ).protocol !== "";
123127
},
124128

125129
//Turn the specified realtive URL into an absolute one. This function
@@ -132,11 +136,11 @@
132136
var relObj = path.parseUrl( relUrl ),
133137
absObj = path.parseUrl( absUrl ),
134138
protocol = relObj.protocol || absObj.protocol,
135-
authority = relObj.authority || absObj.authority || "",
136-
hasPath = relObj.pathname !== undefined,
139+
authority = relObj.authority || absObj.authority,
140+
hasPath = relObj.pathname !== "",
137141
pathname = path.makePathAbsolute( relObj.pathname || absObj.filename, absObj.pathname ),
138142
search = relObj.search || ( !hasPath && absObj.search ) || "",
139-
hash = relObj.hash || "";
143+
hash = relObj.hash;
140144

141145
return protocol + "//" + authority + pathname + search + hash;
142146
},
@@ -223,7 +227,7 @@
223227
//is that links embedded within external documents will refer to the
224228
//application document, whereas links embedded within the application
225229
//document will be resolved against the document base.
226-
if ( u.protocol !== undefined ) {
230+
if ( u.protocol !== "" ) {
227231
return ( u.hash && ( u.hrefNoHash === documentUrl.hrefNoHash || ( documentBaseDiffers && u.hrefNoHash === documentBase.hrefNoHash ) ) );
228232
}
229233
return (/^#/).test( u.href );

0 commit comments

Comments
 (0)