@@ -24,7 +24,7 @@ angularService("$location", function(browser){
24
24
if ( href ) {
25
25
parseUrl ( href ) ;
26
26
} else {
27
- href = check ( 'href' ) || check ( 'protocol' , '://' , 'host' , ':' , 'port' , '' , 'path' , '?' , 'search' ) ;
27
+ href = check ( 'href' ) || checkProtocol ( ) ;
28
28
var hash = check ( 'hash' ) ;
29
29
if ( isUndefined ( hash ) ) hash = checkHashPathSearch ( ) ;
30
30
if ( isDefined ( hash ) ) {
@@ -38,19 +38,22 @@ angularService("$location", function(browser){
38
38
}
39
39
}
40
40
41
- function check ( ) {
42
- var i = - 1 ,
43
- length = arguments . length ,
44
- name , seperator , parts = [ ] ,
45
- value , same = true ;
46
- for ( ; i < length ; i = i + 2 ) {
47
- parts . push ( seperator = ( arguments [ i ] || '' ) ) ;
48
- name = arguments [ i + 1 ] ;
49
- value = location [ name ] ;
50
- parts . push ( typeof value == 'object' ? toKeyValue ( value ) : value ) ;
51
- same = same && equals ( lastLocation [ name ] , value ) ;
52
- }
53
- return same ? undefined : parts . join ( '' ) ;
41
+ function check ( param ) {
42
+ return lastLocation [ param ] == location [ param ] ? undefined : location [ param ] ;
43
+ }
44
+
45
+ function checkProtocol ( ) {
46
+ if ( lastLocation . protocol === location . protocol &&
47
+ lastLocation . host === location . host &&
48
+ lastLocation . port === location . port &&
49
+ lastLocation . path === location . path &&
50
+ equals ( lastLocation . search , location . search ) )
51
+ return undefined ;
52
+ var url = toKeyValue ( location . search ) ;
53
+ var port = ( location . port == DEFAULT_PORTS [ location . protocol ] ? null : location . port ) ;
54
+ return location . protocol + '://' + location . host +
55
+ ( port ? ':' + port : '' ) + location . path +
56
+ ( url ? '?' + url : '' ) ;
54
57
}
55
58
56
59
function checkHashPathSearch ( ) {
@@ -71,9 +74,7 @@ angularService("$location", function(browser){
71
74
location . port = match [ 5 ] || DEFAULT_PORTS [ location . protocol ] || null ;
72
75
location . path = match [ 6 ] ;
73
76
location . search = parseKeyValue ( match [ 8 ] ) ;
74
- location . hash = match [ 9 ] || '' ;
75
- if ( location . hash )
76
- location . hash = location . hash . substr ( 1 ) ;
77
+ location . hash = match [ 10 ] || '' ;
77
78
match = HASH_MATCH . exec ( location . hash ) ;
78
79
location . hashPath = unescape ( match [ 1 ] || '' ) ;
79
80
location . hashSearch = parseKeyValue ( match [ 3 ] ) ;
0 commit comments