jashkenas / jashkenas/backbone

Trailing Fragment Space(s)

Open
#4,198 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

break question
Dominant language
JavaScript
Stars
28.1k
Forks
5.3k
PR merge metrics
No merged PRs in 30d

Description

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);
            },

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the getFragment entry point and inspect the M regular expression shown in the issue, then trace how the returned fragment reaches the outbound/:tieBack/po/:poNbr route. Confirm the expected behavior for a trailing-space parameter and add coverage demonstrating that the router receives the intended value without breaking existing fragment handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.