@@ -675,26 +675,33 @@ function $LocationProvider(){
675
675
676
676
if ( href && href . indexOf ( '://' ) < 0 ) { // Ignore absolute URLs
677
677
var prefix = '#' + hashPrefix ;
678
- if ( href [ 0 ] == '/' ) {
679
- // absolute path - replace old path
680
- absHref = appBase + prefix + href ;
681
- } else if ( href [ 0 ] == '#' ) {
682
- // local anchor
683
- absHref = appBase + prefix + ( $location . path ( ) || '/' ) + href ;
684
- } else {
685
- // relative path - join with current path
686
- var stack = $location . path ( ) . split ( "/" ) ,
687
- parts = href . split ( "/" ) ;
688
- if ( stack . length === 2 && ! stack [ 1 ] ) stack . length = 1 ;
689
- for ( var i = 0 ; i < parts . length ; i ++ ) {
690
- if ( parts [ i ] == "." )
691
- continue ;
692
- else if ( parts [ i ] == ".." )
693
- stack . pop ( ) ;
694
- else if ( parts [ i ] . length )
695
- stack . push ( parts [ i ] ) ;
678
+ var baseHrefNoFile = stripFile ( baseHref ) ;
679
+ if ( href [ 0 ] == '/' && baseHref && beginsWith ( baseHrefNoFile , href ) ) {
680
+ // absolute path - within base or when there's no base
681
+ var hrefNoBase = href . substr ( baseHrefNoFile . length - 1 ) ;
682
+ absHref = appBase + prefix + hrefNoBase ;
683
+ } else if ( href [ 0 ] != '/' ) { // Ignore absolute path outside of base
684
+ if ( beginsWith ( prefix + '/' , href ) ) {
685
+ // local anchor with absolute path
686
+ absHref = appBase + href ;
687
+ } else if ( href [ 0 ] == '#' ) {
688
+ // local anchor
689
+ absHref = appBase + prefix + ( $location . path ( ) || '/' ) + href ;
690
+ } else {
691
+ // relative path - join with current path
692
+ var stack = $location . path ( ) . split ( "/" ) ,
693
+ parts = href . split ( "/" ) ;
694
+ if ( stack . length === 2 && ! stack [ 1 ] ) stack . length = 1 ;
695
+ for ( var i = 0 ; i < parts . length ; i ++ ) {
696
+ if ( parts [ i ] == "." )
697
+ continue ;
698
+ else if ( parts [ i ] == ".." )
699
+ stack . pop ( ) ;
700
+ else if ( parts [ i ] . length )
701
+ stack . push ( parts [ i ] ) ;
702
+ }
703
+ absHref = appBase + prefix + stack . join ( '/' ) ;
696
704
}
697
- absHref = appBase + prefix + stack . join ( '/' ) ;
698
705
}
699
706
}
700
707
}
0 commit comments