Skip to content

Commit

Permalink
Merge pull request #4026 from Flamefork/4025-encoded-fragment
Browse files Browse the repository at this point in the history
Fixed updating URL with uri-decoded value
  • Loading branch information
jridgewell committed May 6, 2016
2 parents dbf8d97 + 57e89d8 commit a530dbe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1814,11 +1814,14 @@
}
var url = rootPath + fragment;

// Strip the hash and decode for matching.
fragment = this.decodeFragment(fragment.replace(pathStripper, ''));
// Strip the fragment of the query and hash for matching.
fragment = fragment.replace(pathStripper, '');

if (this.fragment === fragment) return;
this.fragment = fragment;
// Decode for matching.
var decodedFragment = this.decodeFragment(fragment);

if (this.fragment === decodedFragment) return;
this.fragment = decodedFragment;

// If pushState is available, we use it to set the fragment as a real URL.
if (this._usePushState) {
Expand Down
7 changes: 7 additions & 0 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,4 +1059,11 @@
Backbone.history.start({root: '®ooτ', pushState: true});
});

QUnit.test('#4025 - navigate updates URL hash as is', function(assert) {
assert.expect(1);
var route = 'search/has%20space';
Backbone.history.navigate(route);
assert.strictEqual(location.hash, '#' + route);
});

})();

0 comments on commit a530dbe

Please sign in to comment.