Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Prevent removing trailing slash in request URL #96

Merged

Conversation

alexlafroscia
Copy link
Collaborator

The old way of building a URL was too brittle and didn't cover a lot of the different cases that could take place, in different combinations of the host, namespace, and segment having or not having slashes included.

The new approach implemented here handles the various cases correctly, and ensures that we do not remove a trailing slash if one was provided.

}

function stripSlashes(path) {
if (typeof path === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking for string 3 times, you could either type cast the argument to a string or throw an error if the argument it not a string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

throw an error if the argument it not a string

Which argument? The one to _buildURL?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I'm referring to typeof path === 'string'. You don't need to check the argument type here.

It's safe enough for stripSlashes to either force path argument to be a string or throw an error here if it's not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh okay, gotcha, I'll fix that up.

Is there a reason not to do the check? Like a performance concern? Or is it just unnecessary? removing the checks makes a bunch of tests fail that were passing before.

@taras
Copy link
Contributor

taras commented Apr 23, 2016

Other than one comment, it looks good.

@alexlafroscia alexlafroscia force-pushed the fix-trailing-slash-issue branch 2 times, most recently from 8319202 to 81aa92c Compare April 23, 2016 19:17
@alexlafroscia
Copy link
Collaborator Author

@taras can you review this again? I took care of the issue you mentioned.

@alexlafroscia alexlafroscia changed the title Make URL building great again Prevent messing with trailing slash in request URL May 4, 2016
@alexlafroscia alexlafroscia changed the title Prevent messing with trailing slash in request URL Prevent removing trailing slash in request URL May 4, 2016
@taras
Copy link
Contributor

taras commented May 29, 2016

👍

The check was not actually whether or not a URL was absolute, but
whether it was "complete".  For example, "http://foo.com" should have
been recognized, although that is not actually what an "absolute url"
usually refers to, which is something like "/foo".  The name change just
increases the clarify of what is being verifyied.
The old way of building a URL was too brittle and didn't cover a lot of
the different cases that could take place, in different combinations of
the host, namespace, and segment having or not having slashes included.

The new approach implemented here handles the various cases correctly,
and ensures that we do not remove a trailing slash if one was provided.

Closes ember-cli#70
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants