-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
url: add join method #3174
url: add join method #3174
Conversation
Allows url paths to be combined with similar semantics to path.join. Usage: url.join('http://example.com', 'path', '/to', 'route'); The url module was missing a method to join several different parts of a path together into one normalized url string. Until now, the resolve method has been the closest thing, but only one path could be passed to append to the base url. This functionality works by joining the keeping the source part of the url as-is, combining the rest of the arguments with posix.join, and then calling url.resolve with the source and combined path.
It would be better if the corresponding doc changes are also done in this PR. |
Adds corresponding documentation for url.join method, including a description and three examples of usage.
@thefourtheye Good point, added in 347bd4c |
} | ||
]; | ||
|
||
joinTests.forEach(function (joinTest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running make jslint
on your code changes flags a style issue on this line. (Style in Node core would be function(joinTest)
without any spaces.)
For reference, userland modules that already implement this functionality: |
What's the use case for this? Not trying to be discouraging, but introducing more API surface in a stable core module would require a pretty rock-solid justification. Is there a reason the userland implementations are insufficient? |
This disparity seems like a bug in the implementation:
It seems that |
@Trott I don't think the userland implementations are insufficient, other than the fact that they require another dependency. I ran into a use-case for this functionality the other day, and instead of adding those packages, I ended up using If you think this is something that should be added, let me know and I'll fix the bugs and style issues. If not, that's ok too 😄 |
@Trott Any update on this or shall I close? |
I'm kind of -0 on this. I wouldn't stop another more enthusiastic collaborator from landing it (although it would take two enthusiastic collaborators, really, because it would need at least one But if there is only one overarching philosophy for which there is broad agreement among the collaborators, it would be that Node core should be small and that problems that can be solved in userland should be done in userland. (Some folks on the HTTP working group openly wish the Since @thefourtheye and @ChALkeR have taken some small actions on this PR, I'd be curious if their opinions lined up with mine or not. |
I would like to hear from @domenic |
I don't think this generally makes sense.
What you really want is probably some kind of API specifically designed for the manipulation of a URL object's |
FWIW, i agree with @domenic
the js standard is clear, http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.join |
Thanks for the feedback everyone. |
Allows url paths to be combined with similar semantics to
path.join.
Usage:
The url module was missing a method to join several different
parts of a path together into one normalized url string. Until
now, the resolve method has been the closest thing, but only one
path could be passed to append to the base url.
This functionality works by joining the keeping the source part of
the url as-is, combining the rest of the arguments with posix.join,
and then calling url.resolve with the source and combined path.