* LocationHashbangUrl represents url * This object is exposed as $location service when developer doesn't opt into html5 mode. * It also serves as the base class for html5 mode fallback on legacy browsers. * * @constructor * @param {string} appBase application base URL * @param {string} hashPr
(appBase, hashPrefix)
| 9383 | * @param {string} hashPrefix hashbang prefix |
| 9384 | */ |
| 9385 | function LocationHashbangUrl(appBase, hashPrefix) { |
| 9386 | var appBaseNoFile = stripFile(appBase); |
| 9387 | |
| 9388 | parseAbsoluteUrl(appBase, this, appBase); |
| 9389 | |
| 9390 | |
| 9391 | /** |
| 9392 | * Parse given hashbang url into properties |
| 9393 | * @param {string} url Hashbang url |
| 9394 | * @private |
| 9395 | */ |
| 9396 | this.$$parse = function(url) { |
| 9397 | var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url); |
| 9398 | var withoutHashUrl = withoutBaseUrl.charAt(0) == '#' |
| 9399 | ? beginsWith(hashPrefix, withoutBaseUrl) |
| 9400 | : (this.$$html5) |
| 9401 | ? withoutBaseUrl |
| 9402 | : ''; |
| 9403 | |
| 9404 | if (!isString(withoutHashUrl)) { |
| 9405 | throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url, |
| 9406 | hashPrefix); |
| 9407 | } |
| 9408 | parseAppUrl(withoutHashUrl, this, appBase); |
| 9409 | |
| 9410 | this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase); |
| 9411 | |
| 9412 | this.$$compose(); |
| 9413 | |
| 9414 | /* |
| 9415 | * In Windows, on an anchor node on documents loaded from |
| 9416 | * the filesystem, the browser will return a pathname |
| 9417 | * prefixed with the drive name ('/C:/path') when a |
| 9418 | * pathname without a drive is set: |
| 9419 | * * a.setAttribute('href', '/foo') |
| 9420 | * * a.pathname === '/C:/foo' //true |
| 9421 | * |
| 9422 | * Inside of Angular, we're always using pathnames that |
| 9423 | * do not include drive names for routing. |
| 9424 | */ |
| 9425 | function removeWindowsDriveName (path, url, base) { |
| 9426 | /* |
| 9427 | Matches paths for file protocol on windows, |
| 9428 | such as /C:/foo/bar, and captures only /foo/bar. |
| 9429 | */ |
| 9430 | var windowsFilePathExp = /^\/[A-Z]:(\/.*)/; |
| 9431 | |
| 9432 | var firstPathSegmentMatch; |
| 9433 | |
| 9434 | //Get the relative path from the input URL. |
| 9435 | if (url.indexOf(base) === 0) { |
| 9436 | url = url.replace(base, ''); |
| 9437 | } |
| 9438 | |
| 9439 | // The input URL intentionally contains a first path segment that ends with a colon. |
| 9440 | if (windowsFilePathExp.exec(url)) { |
| 9441 | return path; |
| 9442 | } |
nothing calls this directly
no test coverage detected