Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ClientRequest chop off fragment identifiers from urls #972

Merged
merged 1 commit into from
Dec 1, 2017

Conversation

jleoirab
Copy link
Contributor

This PR tries to make ClientRequest and ExpressServerRequest consistent by ensuring the that fragment identifiers are chopped of from urls in ClientRequest and that they are not included when getUrl is called.

@CLAassistant
Copy link

CLAassistant commented Nov 30, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@roblg roblg 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 the submission! I left a couple comments.

console.error("An Invalid url was provided");
} else {
this._url = match[1];
}
Copy link
Member

Choose a reason for hiding this comment

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

Couple requests for this section:

  • I think for the purposes of this PR, I'd prefer not to log anything in the case an "invalid" URL was provided. We could/should validate the URL that we're given, but if we were doing that I'd probably want to throw rather than just log, and that's considerably more involved than stripping the hash off the end, so we can put that aside for now.
  • I'd like to keep the two assignments to this._url in constructor closer together. Feel free to move the first one down into your first if-case.

This doesn't apply to this specific PR, since I'd like to remove the new logging anyway, but for future react-server submissions, we've got a logger set up in react-server that ensures that we get log messages to the appropriate places w/ the appropriate severity levels. In general, rather than console.error, we should use that setup (if you search for "logger" in the code, it should be easy to find examples).

clientRequest = new ClientRequest("/react-server/foo/?foo=bar&baz=123&zed=abc?#some-fragment?#");
expect(clientRequest.getUrl()).toEqual("/react-server/foo/?foo=bar&baz=123&zed=abc?");
done();
});
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding tests!

One additional test I'd like to see here is a test that has a URL with a ? following the #. e.g. /react-server/foo#?bar=3&foo=7. I feel like I've seen libraries that store data in the hash in that format, and because we're looking for both # and ? in regexes in ClientRequest, it seems like a place we could have regressions in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, what would the expected behavior be? Based on this:

https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax

It seems like it will be wrong to store the part after the ? as as query params in this case since it does not comply with the uri syntax.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I'd expect that everything after the # is stripped -- it's still part of the hash, and not the query string. The concern would be that something in the code changes later, and all of a sudden we start matching the ? before the # or something, and it accidentally gets included as the query string. A test case should help prevent that kind of regression.

@jleoirab jleoirab force-pushed the remove-hash-from-client-request-url branch from b108f38 to 2388c6a Compare December 1, 2017 00:32
@gigabo
Copy link
Contributor

gigabo commented Dec 1, 2017

This looks good to me with the latest changes. Nice fix @j-beatzz.

@gigabo gigabo added the bug An issue with the system label Dec 1, 2017
@roblg roblg merged commit fe2fb1f into redfin:master Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants