Simplify.

This commit is contained in:
Brad Dunbar
2015-04-28 07:13:54 -04:00
parent 24daf350e4
commit c8968853a2
2 changed files with 27 additions and 6 deletions

View File

@@ -1529,7 +1529,9 @@
// Does the pathname match the root?
matchRoot: function() {
return this.rootMatcher.test(this.location.pathname);
var path = this.decodeFragment(this.location.pathname);
var root = path.slice(0, this.root.length - 1) + '/';
return root === this.root;
},
// Unicode characters in `location.pathname` are percent encoded so they're
@@ -1594,11 +1596,6 @@
// Normalize root to always include a leading and trailing slash.
this.root = ('/' + this.root + '/').replace(rootStripper, '/');
// A regular expression for testing the pathname against the root.
this.rootMatcher = new RegExp(
'^' + this.root.slice(0, -1).replace(escapeRegExp, '\\$&') + '(/|$)'
);
// Transition from hashChange to pushState or vice versa if both are
// requested.
if (this._wantsHashChange && this._wantsPushState) {

View File

@@ -968,4 +968,28 @@
Backbone.history.start({root: 'x+y.z', pushState: true});
});
test("roots with unicode characters", 1, function() {
location.replace('http://example.com/®ooτ/foo');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {'foo': 'foo'},
foo: function(){ ok(true); }
});
var router = new Router;
Backbone.history.start({root: '®ooτ', pushState: true});
});
test("roots without slash", 1, function() {
location.replace('http://example.com/®ooτ');
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {location: location});
var Router = Backbone.Router.extend({
routes: {'': 'index'},
index: function(){ ok(true); }
});
var router = new Router;
Backbone.history.start({root: '®ooτ', pushState: true});
});
})();