mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-17 19:11:08 +00:00
fix up the $location encoding
This commit is contained in:
parent
af1eb6914e
commit
cdda664f89
4 changed files with 18 additions and 6 deletions
|
|
@ -6,6 +6,10 @@
|
||||||
</head>
|
</head>
|
||||||
<body ng:init="$window.$scope = this">
|
<body ng:init="$window.$scope = this">
|
||||||
<pre>$location={{$location}}</pre>
|
<pre>$location={{$location}}</pre>
|
||||||
|
Hash Search:
|
||||||
|
<ul>
|
||||||
|
<li ng:repeat="(key, value) in $location.hashSearch"><tt>{{key}}={{value}}</tt></li>
|
||||||
|
</ul>
|
||||||
<hr/>
|
<hr/>
|
||||||
href: <input type="text" name="$location.href" size="120"/> <br/>
|
href: <input type="text" name="$location.href" size="120"/> <br/>
|
||||||
hash: <input type="text" name="$location.hash" size="120"/> <br/>
|
hash: <input type="text" name="$location.hash" size="120"/> <br/>
|
||||||
|
|
|
||||||
|
|
@ -352,8 +352,8 @@ function parseKeyValue(keyValue) {
|
||||||
foreach((keyValue || "").split('&'), function(keyValue){
|
foreach((keyValue || "").split('&'), function(keyValue){
|
||||||
if (keyValue) {
|
if (keyValue) {
|
||||||
key_value = keyValue.split('=');
|
key_value = keyValue.split('=');
|
||||||
key = decodeURIComponent(key_value[0]);
|
key = unescape(key_value[0]);
|
||||||
obj[key] = key_value[1] ? decodeURIComponent(key_value[1]) : true;
|
obj[key] = key_value[1] ? unescape(key_value[1]) : true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
|
|
@ -362,7 +362,7 @@ function parseKeyValue(keyValue) {
|
||||||
function toKeyValue(obj) {
|
function toKeyValue(obj) {
|
||||||
var parts = [];
|
var parts = [];
|
||||||
foreach(obj, function(value, key){
|
foreach(obj, function(value, key){
|
||||||
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
|
parts.push(escape(key) + '=' + escape(value));
|
||||||
});
|
});
|
||||||
return parts.length ? parts.join('&') : '';
|
return parts.length ? parts.join('&') : '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ angularService("$location", function(browser){
|
||||||
} else {
|
} else {
|
||||||
href = check('href') || check('protocol', '://', 'host', ':', 'port', '', 'path', '?', 'search');
|
href = check('href') || check('protocol', '://', 'host', ':', 'port', '', 'path', '?', 'search');
|
||||||
var hash = check('hash');
|
var hash = check('hash');
|
||||||
if (isUndefined(hash)) hash = check('hashPath', '?', 'hashSearch');
|
if (isUndefined(hash)) hash = checkHashPathSearch();
|
||||||
if (isDefined(hash)) {
|
if (isDefined(hash)) {
|
||||||
href = (href || location.href).split('#')[0];
|
href = (href || location.href).split('#')[0];
|
||||||
href+= '#' + hash;
|
href+= '#' + hash;
|
||||||
|
|
@ -53,6 +53,14 @@ angularService("$location", function(browser){
|
||||||
return same ? undefined : parts.join('');
|
return same ? undefined : parts.join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkHashPathSearch(){
|
||||||
|
if (lastLocation.hashPath === location.hashPath &&
|
||||||
|
equals(lastLocation.hashSearch, location.hashSearch) )
|
||||||
|
return undefined;
|
||||||
|
var url = toKeyValue(location.hashSearch);
|
||||||
|
return escape(location.hashPath) + (url ? '?' + url : '');
|
||||||
|
}
|
||||||
|
|
||||||
function parseUrl(url){
|
function parseUrl(url){
|
||||||
if (isDefined(url)) {
|
if (isDefined(url)) {
|
||||||
var match = URL_MATCH.exec(url);
|
var match = URL_MATCH.exec(url);
|
||||||
|
|
@ -67,7 +75,7 @@ angularService("$location", function(browser){
|
||||||
if (location.hash)
|
if (location.hash)
|
||||||
location.hash = location.hash.substr(1);
|
location.hash = location.hash.substr(1);
|
||||||
match = HASH_MATCH.exec(location.hash);
|
match = HASH_MATCH.exec(location.hash);
|
||||||
location.hashPath = match[1] || '';
|
location.hashPath = unescape(match[1] || '');
|
||||||
location.hashSearch = parseKeyValue(match[3]);
|
location.hashSearch = parseKeyValue(match[3]);
|
||||||
|
|
||||||
copy(location, lastLocation);
|
copy(location, lastLocation);
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ describe("service", function(){
|
||||||
scope.$location.hashPath = 'page=http://path';
|
scope.$location.hashPath = 'page=http://path';
|
||||||
scope.$location.hashSearch = {k:'a=b'};
|
scope.$location.hashSearch = {k:'a=b'};
|
||||||
|
|
||||||
expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page=http://path?k=a%3Db');
|
expect(scope.$location.toString()).toEqual('http://host:123/p/a/t/h.html?query=value#page%3Dhttp%3A//path?k=a%3Db');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should parse file://', function(){
|
it('should parse file://', function(){
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue