jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.09k stars 5.39k forks source link

Trailing Fragment Space(s) #4198

Open kev22257 opened 6 years ago

kev22257 commented 6 years ago

We have fragments that have a space at the end (outbound/22130600/po/powithspacetest%20). When trying to navigate to this fragment Backbone is stripping the trailing space in getFragment().

        var M = /^[#\/]|\s+$/g;

        getFragment: function(t) {
            if (t == null) {
                if (this._usePushState || !this._wantsHashChange) {
                    t = this.getPath()
                } else {
                    t = this.getHash()
                }
            }
            return t.replace(M, "")
        },

I can understand removing the bits at the start of the fragment, but can someone explain the motivation for removing the space(s) at the end? This causes our app to fail to lookup the requested data because the part with the space is a param in the router.

routes: {
                "": "home",
                "outbound/:tieBack/po/:poNbr": "outboundDetail"
            },

And

            outboundDetail: function(tieBack, poNbr) {
                app.switchOutboundDetail(tieBack, poNbr);
            },
jgonggrijp commented 2 years ago

Since somebody went out of his or her way to strip trailing spaces, it's probably a solution to some kind of problem, so I'll need to consult the version history in order to find the rationale. In any case, I agree it seems a bit overzealous.