diff --git a/backbone.js b/backbone.js index 55ccb22bd..72bb332d9 100644 --- a/backbone.js +++ b/backbone.js @@ -1763,7 +1763,7 @@ // Checks the current URL to see if it has changed, and if it has, // calls `loadUrl`, normalizing across the hidden iframe. checkUrl: function(e) { - var current = this.getFragment(); + var current = this.decodeFragment(this.getFragment()); // If the user pressed the back button, the iframe's hash will have // changed and we should use that for comparison. @@ -1782,7 +1782,8 @@ loadUrl: function(fragment) { // If the root doesn't match, no routes can match either. if (!this.matchRoot()) return false; - fragment = this.fragment = this.getFragment(fragment); + fragment = this.getFragment(fragment); + this.fragment = this.decodeFragment(fragment); return _.some(this.handlers, function(handler) { if (handler.route.test(fragment)) { handler.callback(fragment); diff --git a/test/router.js b/test/router.js index 13110c451..55392c91d 100644 --- a/test/router.js +++ b/test/router.js @@ -72,6 +72,8 @@ var Router = Backbone.Router.extend({ count: 0, + UTFCount: 0, + anythingCount: 0, routes: { 'noCallback': 'noCallback', @@ -114,6 +116,7 @@ }, charUTF: function() { + this.UTFCount++; this.charType = 'UTF'; }, @@ -159,6 +162,7 @@ }, anything: function(whatever) { + this.anythingCount++; this.anything = whatever; }, @@ -426,6 +430,70 @@ assert.equal(router.charType, 'UTF'); }); + QUnit.test('#4085 - Hashes with UTF8 in them.', function(assert) { + var done = assert.async(); + + assert.expect(4); + router.anythingCount = router.UTFCount = 0; + Backbone.history.navigate('charñ', {trigger: true}); + assert.equal(router.UTFCount, 1); + assert.equal(router.anythingCount, 0); + + setTimeout(function() { + assert.equal(router.UTFCount, 1); + assert.equal(router.anythingCount, 0); + done(); + }, 1000); + }); + + QUnit.test('#4085 - Hashes with UTF8 in them, no trigger.', function(assert) { + var done = assert.async(); + + assert.expect(4); + router.anythingCount = router.UTFCount = 0; + Backbone.history.navigate('charñ', {trigger: false}); + assert.equal(router.UTFCount, 0); + assert.equal(router.anythingCount, 0); + + setTimeout(function() { + assert.equal(router.UTFCount, 0); + assert.equal(router.anythingCount, 0); + done(); + }, 1000); + }); + + QUnit.test('#4085 - Hashes with UTF8 in them, replace.', function(assert) { + var done = assert.async(); + + assert.expect(4); + router.anythingCount = router.UTFCount = 0; + Backbone.history.navigate('charñ', {trigger: true, replace: true}); + assert.equal(router.UTFCount, 1); + assert.equal(router.anythingCount, 0); + + setTimeout(function() { + assert.equal(router.UTFCount, 1); + assert.equal(router.anythingCount, 0); + done(); + }, 1000); + }); + + QUnit.test('#4085 - Hashes with UTF8 in them, replace, no trigger.', function(assert) { + var done = assert.async(); + + assert.expect(4); + router.anythingCount = router.UTFCount = 0; + Backbone.history.navigate('charñ', {trigger: false, replace: true}); + assert.equal(router.UTFCount, 0); + assert.equal(router.anythingCount, 0); + + setTimeout(function() { + assert.equal(router.UTFCount, 0); + assert.equal(router.anythingCount, 0); + done(); + }, 1000); + }); + QUnit.test('#1185 - Use pathname when hashChange is not wanted.', function(assert) { assert.expect(1); Backbone.history.stop();