GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: Adding note about empty strings in path module by thefourtheye · Pull Request #2106 · nodejs/node

Conversation

@thefourtheye

@thefourtheye thefourtheye commented Jul 5, 2015

Copy link
Copy Markdown
Contributor

The path module's join, normalize, isAbsolute, relative and resolve
functions return/use the current directory if they are passed zero
length strings.

> process.version
'v2.3.4-pre'
> path.join('')
'.'
> path.win32.join('')
'.'
> path.posix.join('')
'.'
> path.win32.normalize('')
'.'
> path.posix.normalize('')
'.'
> path.win32.isAbsolute('')
false
> path.posix.isAbsolute('')
false
> path.win32.relative('', '')
''
> path.posix.relative('', '')
''
> path.win32.relative('.', '')
''
> path.posix.relative('.', '')
''
> path.posix.resolve('')
'/home/thefourtheye/Desktop'
> path.win32.resolve('')
'\\home\\thefourtheye\\Desktop'

Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in path's
documentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye thefourtheye mentioned this pull request Jul 5, 2015
path: Throwing error on zero length strings #2105
Closed
@mscdex mscdex added doc Issues and PRs related to Node.js documentation. path Issues and PRs related to the path subsystem. labels Jul 5, 2015
@Trott

Trott commented Jul 6, 2015

Copy link
Copy Markdown
Member

nit: I think empty string is clearer than zero length string. Or, at least, zero-length string instead of zero length string.

Nit aside, LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brendanashworth
brendanashworth reviewed Jul 6, 2015
View reviewed changes
Comment thread doc/api/path.markdown Outdated

@brendanashworth brendanashworth Jul 6, 2015

Copy link
Copy Markdown
Contributor

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.

I'm not sure whether this is really clarifying anything?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

@brendanashworth Since it is a special case, I thought it would be better to document that as well. We can remove it, if it doesn't make much sense to keep.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@brendanashworth brendanashworth Jul 6, 2015

Copy link
Copy Markdown
Contributor

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.

Your call - imo I would throw on this, but that is out of the picture so I'll leave it up to you.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

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.

@brendanashworth Well, in other cases empty string means the current directory, and this is an exception. So, I think it would be better to leave it in.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thefourtheye
thefourtheye force-pushed the path-doc-fix branch from 809d8de to 63874da Compare July 6, 2015 07:10
@thefourtheye

thefourtheye commented Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

@Trott I have read in few places in the Internet that empty string sometimes means a string with only space characters as well. So, I ll better go with zero-length string. Thanks for the suggestion :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jul 6, 2015

Copy link
Copy Markdown
Contributor

I like where this is going! I feel like the wording of "the path" could be a little bit ambiguous for some of them, like path.resolve though. Thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

@brendanashworth Oh yeah, will path string passed as parameter be fine?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brendanashworth

brendanashworth commented Jul 6, 2015

Copy link
Copy Markdown
Contributor

@thefourtheye that doesn't specify which path string ([from ...], to?). I'm not familiar with the case enough it seems - do all/any of the path strings trigger this case? I think it should specify whether it is from / to if not.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

@brendanashworth It is applicable to both from and to. How can I better phrase it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 6, 2015

Copy link
Copy Markdown
Contributor Author

@brendanashworth I updated the messages a little bit based on your suggestion. PTAL. cc @Trott

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fishrock123
Fishrock123 reviewed Jul 6, 2015
View reviewed changes
Comment thread doc/api/path.markdown Outdated

@Fishrock123 Fishrock123 Jul 6, 2015

Copy link
Copy Markdown
Contributor

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.

IIRC the behaviour varies on win32 and posix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Trott Trott Jul 6, 2015

Copy link
Copy Markdown
Member

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.

If they aren't there already, maybe add tests for the situations covered by these notes and see what happens on CI. Then you will know for sure whether the behavior is universal or platform-dependent. Include comments indicating that the tests are there to cover edge cases noted in the documentation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

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.

@Fishrock123 I don't have a Windows machine, but when I tried in REPL, I got false for both the versions.

@Trott Thanks for the suggestion man :-) I included a simple test now. PTAL.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Trott Trott Jul 7, 2015

Copy link
Copy Markdown
Member

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.

CI: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/121/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thefourtheye thefourtheye Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

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.

@Trott Thank you :-) Looks like the test is passing in all the environments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Trott Trott Jul 12, 2015

Copy link
Copy Markdown
Member

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.

Just manually tested on Windows for good measure, and path.isAbsolute('') returned false. So that seems OK.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thefourtheye added 2 commits July 8, 2015 01:04
@thefourtheye
doc: Adding note about empty strings in path module
1b6838f
The path module's `join, normalize, isAbsolute, relative and resolve`
functions return/use the current directory if they are passed zero
length strings.

    > process.version
    'v2.3.4-pre'
    > path.win32.join('')
    '.'
    > path.posix.join('')
    '.'
    > path.win32.normalize('')
    '.'
    > path.posix.normalize('')
    '.'
    > path.win32.isAbsolute('')
    false
    > path.posix.isAbsolute('')
    false
    > path.win32.relative('', '')
    ''
    > path.posix.relative('', '')
    ''
    > path.win32relative('.', '')
    ''
    > path.posix.relative('.', '')
    ''
    > path.posix.resolve('')
    '/home/thefourtheye/Desktop'
    > path.win32.resolve('')
    '\\home\\thefourtheye\\Desktop'

Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in `path`'s
documentation.
@thefourtheye
test: zero-length strings with path module functions
a65d5fd
These testcases are specific to one uncommon behaviour in path module.
Few of the functions in path module, treat '' strings as current working
directory. This test makes sure that the behaviour is intact between
commits. See: nodejs#2106
@thefourtheye
thefourtheye force-pushed the path-doc-fix branch from 10b2405 to a65d5fd Compare July 7, 2015 20:00
@thefourtheye

thefourtheye commented Jul 11, 2015

Copy link
Copy Markdown
Contributor Author

Bump!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Jul 12, 2015

Copy link
Copy Markdown
Member

LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Jul 12, 2015

Copy link
Copy Markdown
Member

Unless someone beats me to it or raises an objection between now and then, I'll merge this some time in the next 48 to 72 hours (roughly some time on Tuesday PDT).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thefourtheye

thefourtheye commented Jul 12, 2015

Copy link
Copy Markdown
Contributor Author

Thanks @Trott :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott

Trott commented Jul 14, 2015

Copy link
Copy Markdown
Member

Rebased against master and running CI one more time for good measure: https://jenkins-iojs.nodesource.com/job/iojs+any-pr+multi/150/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Trott pushed a commit to Trott/io.js that referenced this pull request Jul 14, 2015
@thefourtheye @Trott
doc,test: empty strings in path module
65963ec
The path module's `join, normalize, isAbsolute, relative and resolve`
functions return/use the current directory if they are passed zero
length strings.

    > process.version
    'v2.3.4-pre'
    > path.win32.join('')
    '.'
    > path.posix.join('')
    '.'
    > path.win32.normalize('')
    '.'
    > path.posix.normalize('')
    '.'
    > path.win32.isAbsolute('')
    false
    > path.posix.isAbsolute('')
    false
    > path.win32.relative('', '')
    ''
    > path.posix.relative('', '')
    ''
    > path.win32relative('.', '')
    ''
    > path.posix.relative('.', '')
    ''
    > path.posix.resolve('')
    '/home/thefourtheye/Desktop'
    > path.win32.resolve('')
    '\\home\\thefourtheye\\Desktop'

Since empty paths are not valid in any of the operating systems people
normally use, this behaviour might be a surprise to the users. This
commit introduces "Notes" about this, wherever applicable in `path`'s
documentation.

The tests makes sure that the behaviour is intact between
commits.

PR-URL: nodejs#2106
Reviewed-By: Rich Trott <[email protected]>
@Trott

Trott commented Jul 14, 2015

Copy link
Copy Markdown
Member

merged in 65963ec

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott closed this Jul 14, 2015
@thefourtheye
thefourtheye deleted the path-doc-fix branch July 14, 2015 16:22
@thefourtheye

thefourtheye commented Jul 14, 2015

Copy link
Copy Markdown
Contributor Author

@Trott Thanks :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fishrock123 Fishrock123 mentioned this pull request Jul 16, 2015
Release Proposal: v2.4.0 #2189
Merged
@eush77 eush77 mentioned this pull request Jan 23, 2016
path.relative(dir, dir) returns empty string #4826
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

doc Issues and PRs related to Node.js documentation. path Issues and PRs related to the path subsystem.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@thefourtheye @Trott @brendanashworth @Fishrock123 @mscdex
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.