File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change 18511851 // Is pushState desired ... is it available?
18521852 this . options = _ . extend ( { root : '/' } , this . options , options ) ;
18531853 this . root = this . options . root ;
1854+ this . _trailingSlash = this . options . trailingSlash || false ;
18541855 this . _wantsHashChange = this . options . hashChange !== false ;
18551856 this . _hasHashChange = 'onhashchange' in window && ( document . documentMode === void 0 || document . documentMode > 7 ) ;
18561857 this . _useHashChange = this . _wantsHashChange && this . _hasHashChange ;
19931994 // Normalize the fragment.
19941995 fragment = this . getFragment ( fragment || '' ) ;
19951996
1996- // Don't include a trailing slash on the root.
1997+ // Strip trailing slash on the root unless _trailingSlash is true
19971998 var rootPath = this . root ;
1998- if ( fragment === '' || fragment . charAt ( 0 ) === '?' ) {
1999- rootPath = rootPath . slice ( 0 , - 1 ) || '/' ;
1999+ if ( ! this . _trailingSlash && ( fragment === '' || fragment . charAt ( 0 ) === '?' ) ) {
2000+ rootPath = rootPath . slice ( 0 , - 1 ) || '/' ; // rootPath must always have at least '/'
20002001 }
20012002 var url = rootPath + fragment ;
20022003
Original file line number Diff line number Diff line change 807807 Backbone . history . navigate ( '?x=1' ) ;
808808 } ) ;
809809
810+ QUnit . test ( '#3391 - Empty root normalizes to single slash.' , function ( assert ) {
811+ assert . expect ( 1 ) ;
812+ Backbone . history . stop ( ) ;
813+ Backbone . history = _ . extend ( new Backbone . History , {
814+ location : location ,
815+ history : {
816+ pushState : function ( state , title , url ) {
817+ assert . strictEqual ( url , '/' ) ;
818+ }
819+ }
820+ } ) ;
821+ location . replace ( 'http://example.com/root/path' ) ;
822+ Backbone . history . start ( { pushState : true , hashChange : false , root : '' } ) ;
823+ Backbone . history . navigate ( '' ) ;
824+ } ) ;
825+
826+ QUnit . test ( '#3391 - Use trailing slash on root when trailingSlash is true.' , function ( assert ) {
827+ assert . expect ( 1 ) ;
828+ Backbone . history . stop ( ) ;
829+ Backbone . history = _ . extend ( new Backbone . History , {
830+ location : location ,
831+ history : {
832+ pushState : function ( state , title , url ) {
833+ assert . strictEqual ( url , '/root/' ) ;
834+ }
835+ }
836+ } ) ;
837+ location . replace ( 'http://example.com/root/path' ) ;
838+ Backbone . history . start ( { pushState : true , hashChange : false , root : 'root' , trailingSlash : true } ) ;
839+ Backbone . history . navigate ( '' ) ;
840+ } ) ;
841+
810842 QUnit . test ( '#2765 - Fragment matching sans query/hash.' , function ( assert ) {
811843 assert . expect ( 2 ) ;
812844 Backbone . history . stop ( ) ;
You can’t perform that action at this time.
0 commit comments