Skip to content

Middleware: Pass non-branch query parameters on redirect#81

Merged
sirreal merged 3 commits intomasterfrom
update/pass-query-params
Jan 12, 2019
Merged

Middleware: Pass non-branch query parameters on redirect#81
sirreal merged 3 commits intomasterfrom
update/pass-query-params

Conversation

@dmsnell
Copy link
Copy Markdown
Member

@dmsnell dmsnell commented Dec 18, 2018

Resolves #79

When we remap a given URL from calypso.live?branch=... to the
"subdomain" URL we have been stripping away the entire query string when
redirecting the browser. This causes problems when we want to pass flags
to Calypso or otherwise send query args.

In this change we're appending the existing query string without the
branch name specified so that we can pass everything else through.

No query arg named branch will pass through though.

Testing

I need help testing this. I think the local environment is different than the
production one with subdomains and so I don't know if I can get this flow
fully tested locally.

@dmsnell dmsnell requested review from blowery and sirreal December 18, 2018 23:32
Copy link
Copy Markdown
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at this! I left a question about encoding.

I always have difficulty testing changes to this codebase, so I don't think I can help much there.

Comment thread src/middlewares.ts Outdated

const query =
Object.keys( req.query )
.reduce( ( q, key ) => key === 'branch' ? q : q.concat( `${ key }=${ q[ key as keyof {} ] }` ), [] )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express seems to decode the query:

https://expressjs.com/en/api.html#req.query

Should we passing key and value through encodeURIComponent to build the URL below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds like a good catch there @sirreal and yah I agree - let's encode them. I'm AFK now for a couple weeks so feel free to commandeer the PR.

dmsnell and others added 3 commits January 12, 2019 17:04
Resolves #79

When we remap a given URL from `calypso.live?branch=...` to the
"subdomain" URL we have been stripping away the entire query string when
redirecting the browser. This causes problems when we want to pass flags
to Calypso or otherwise send query args.

In this change we're appending the existing query string without the
branch name specified so that we can pass everything else through.

No query arg named `branch` will pass through though.
@sirreal sirreal force-pushed the update/pass-query-params branch from ca281a4 to f6ca587 Compare January 12, 2019 16:04
Copy link
Copy Markdown
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added encoding for the query keys and values, this looks like it should fix.

I'll try landing this over the weekend.

@sirreal sirreal merged commit 2abbade into master Jan 12, 2019
@sirreal sirreal deleted the update/pass-query-params branch January 12, 2019 16:07
sirreal added a commit that referenced this pull request Jan 12, 2019
sirreal added a commit that referenced this pull request Jan 12, 2019
sirreal added a commit that referenced this pull request Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Branch redirection drops query args

2 participants