* 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)
| 9416 | * @param {string} hashPrefix hashbang prefix |
| 9417 | */ |
| 9418 | function LocationHashbangUrl(appBase, hashPrefix) { |
| 9419 | var appBaseNoFile = stripFile(appBase); |
| 9420 | |
| 9421 | parseAbsoluteUrl(appBase, this, appBase); |
| 9422 | |
| 9423 | |
| 9424 | /** |
| 9425 | * Parse given hashbang url into properties |
| 9426 | * @param {string} url Hashbang url |
| 9427 | * @private |
| 9428 | */ |
| 9429 | this.$$parse = function(url) { |
| 9430 | var withoutBaseUrl = beginsWith(appBase, url) || beginsWith(appBaseNoFile, url); |
| 9431 | var withoutHashUrl = withoutBaseUrl.charAt(0) == '#' |
| 9432 | ? beginsWith(hashPrefix, withoutBaseUrl) |
| 9433 | : (this.$$html5) |
| 9434 | ? withoutBaseUrl |
| 9435 | : ''; |
| 9436 | |
| 9437 | if (!isString(withoutHashUrl)) { |
| 9438 | throw $locationMinErr('ihshprfx', 'Invalid url "{0}", missing hash prefix "{1}".', url, |
| 9439 | hashPrefix); |
| 9440 | } |
| 9441 | parseAppUrl(withoutHashUrl, this, appBase); |
| 9442 | |
| 9443 | this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase); |
| 9444 | |
| 9445 | this.$$compose(); |
| 9446 | |
| 9447 | /* |
| 9448 | * In Windows, on an anchor node on documents loaded from |
| 9449 | * the filesystem, the browser will return a pathname |
| 9450 | * prefixed with the drive name ('/C:/path') when a |
| 9451 | * pathname without a drive is set: |
| 9452 | * * a.setAttribute('href', '/foo') |
| 9453 | * * a.pathname === '/C:/foo' //true |
| 9454 | * |
| 9455 | * Inside of Angular, we're always using pathnames that |
| 9456 | * do not include drive names for routing. |
| 9457 | */ |
| 9458 | function removeWindowsDriveName (path, url, base) { |
| 9459 | /* |
| 9460 | Matches paths for file protocol on windows, |
| 9461 | such as /C:/foo/bar, and captures only /foo/bar. |
| 9462 | */ |
| 9463 | var windowsFilePathExp = /^\/[A-Z]:(\/.*)/; |
| 9464 | |
| 9465 | var firstPathSegmentMatch; |
| 9466 | |
| 9467 | //Get the relative path from the input URL. |
| 9468 | if (url.indexOf(base) === 0) { |
| 9469 | url = url.replace(base, ''); |
| 9470 | } |
| 9471 | |
| 9472 | // The input URL intentionally contains a first path segment that ends with a colon. |
| 9473 | if (windowsFilePathExp.exec(url)) { |
| 9474 | return path; |
| 9475 | } |
nothing calls this directly
no test coverage detected