mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Simplify.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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});
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user