diff options
| author | Jeff Cross | 2013-11-26 11:36:36 -0800 |
|---|---|---|
| committer | Jeff Cross | 2013-11-26 18:31:27 -0800 |
| commit | 736c8fbbae57a209f4ba570e38cc3bd0745a9569 (patch) | |
| tree | 7f6516f1792fc2a1e1828d38228542c4c40c748d /src/ng/location.js | |
| parent | 947562220d7d1c851f138a816f7530738b97e7b6 (diff) | |
| download | angular.js-736c8fbbae57a209f4ba570e38cc3bd0745a9569.tar.bz2 | |
refactor($location): move file://+win path fix to $location
The urlResolve method was fixed to automatically remove the
volume label from path names to fix issues with the file
protocol on windows where $location.path() was returning
paths where the first segment would be the volume name,
such as "/C:/mypath". See #4942 and #4928
However, the solution was specific to the $location non-
HTML5 mode, and was implemented at a lower level of
abstraction than it should have been. This refactor moves
the fix to inside of the LocationHashBangUrl $$parse method.
Closes #5041
Diffstat (limited to 'src/ng/location.js')
| -rw-r--r-- | src/ng/location.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/ng/location.js b/src/ng/location.js index f06a5f81..402db3cf 100644 --- a/src/ng/location.js +++ b/src/ng/location.js @@ -179,7 +179,47 @@ function LocationHashbangUrl(appBase, hashPrefix) { hashPrefix); } parseAppUrl(withoutHashUrl, this, appBase); + + this.$$path = removeWindowsDriveName(this.$$path, withoutHashUrl, appBase); + this.$$compose(); + + /* + * In Windows, on an anchor node on documents loaded from + * the filesystem, the browser will return a pathname + * prefixed with the drive name ('/C:/path') when a + * pathname without a drive is set: + * * a.setAttribute('href', '/foo') + * * a.pathname === '/C:/foo' //true + * + * Inside of Angular, we're always using pathnames that + * do not include drive names for routing. + */ + function removeWindowsDriveName (path, url, base) { + /* + Matches paths for file protocol on windows, + such as /C:/foo/bar, and captures only /foo/bar. + */ + var windowsFilePathExp = /^\/?.*?:(\/.*)/; + + var firstPathSegmentMatch; + + //Get the relative path from the input URL. + if (url.indexOf(base) === 0) { + url = url.replace(base, ''); + } + + /* + * The input URL intentionally contains a + * first path segment that ends with a colon. + */ + if (windowsFilePathExp.exec(url)) { + return path; + } + + firstPathSegmentMatch = windowsFilePathExp.exec(path); + return firstPathSegmentMatch ? firstPathSegmentMatch[1] : path; + } }; /** |
