Backbone: Routing case sensitivity

Created on 12 Apr 2015  ·  5Comments  ·  Source: jashkenas/backbone

There should be an option to set the routs to be case sensitive or not

Somthing like this

var Router = Backbone.Router.extend({
    routes: {
        "/": "home"
    },
    ignoreCase:true
});
change wontfix

All 5 comments

Use a regex for your route and the flag i (case insensitive). Es.: /regex/i

var Router = Backbone.Router.extend({
    routes: {
        /regex/i: "home"
    }
    ....
});

You can manually add case-insensitive regex routes inside #initialize.

I understand the spec for URLs specifies case sensitivity, but the fact that your solution requires a good bit of deviation from the normal way routes are specified can cause a lot of headaches. There are countless bits of web software that have deviated from the official specs because it turned out that the official specs didn't consider some important use cases. I'm not suggesting you deviate from the spec in your default behavior, but not offering the option to turn off case sensitivity because "that's the spec" is ignoring all of the actual, real-world demand for that behavior. We're running .NET on IIS, neither of which demand case-sensitive URLs, so requiring all of our developers to go back and fix all of the thousands of URLs scattered throughout the project just to satisfy the spec just isn't going to happen. There are stack overflow questions about this, people posting hacks and workarounds online, all because you're prioritizing the W3C's spec over actual, real-world users.

If you won't allow this as an option, at least expose the related code in backbone (which is currently in a closure) so that we can override this behavior without modifying the original source.

In fact, the spec doesn't actually say that URLs are case sensitive:

"URLs _in general_ are case-sensitive (with the exception of machine names). There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive. /u"

"In general" != "have to be." It says that users should always consider them case-sensitive, but that's because if they don't, they may not properly if the router/server is configured for case sensitivity.

I feel like if apache can be configured for case-insensitivy out of the box, Backbone should be the same way.

This solution also doesn't help in cases where the router's root is what contains the case error.

For example, if the app is not sitting on the root of a domain, like in the case of www.example.com/MyApp, then your regex solution is not going to help when a user types in www.example.com/myapp.

Was this page helpful?
0 / 5 - 0 ratings