path.basename return directroy #4520

Closed
AndreasMadsen opened this Issue Jan 4, 2013 · 10 comments

Comments

Projects
None yet
5 participants
Member

AndreasMadsen commented Jan 4, 2013

The curent behaviour is:

console.log(path.basename('/dir/')) // 'dir/'

I sugest that a better behavior would be an empty string.

Owner

bnoordhuis commented Jan 4, 2013

I agree that the current behavior is unhelpful (if not flat out wrong). However, consider the following:

$ python -c 'import os; print(os.path.basename("/dir/"))'

$ perl -MFile::Basename -e 'print File::Basename::basename("/dir/")'
dir
$ ruby -e 'print File.basename("/dir/")'
dir

Other scripting environments take different approaches. Which one do we want to follow?

@bnoordhuis even the GNU coreutils basename program returns dir:

$ basename /dir/
dir

bmeck commented Jan 8, 2013

http://ss64.com/nt/syntax-args.html , cmd.exe / DOS appear to be in the empty result boat (see %~n1).

Keeping with all the unix names I would think GNU and BSD basename would be the defining behavior ( http://www.unix.com/man-page/FreeBSD/3/basename/ ).

+1 for dir

Owner

bnoordhuis commented Jan 8, 2013

Okay, let's go with 'dir'. Who is going to write the patch?

Member

AndreasMadsen commented Jan 8, 2013

I will take the honor of that :)

Member

AndreasMadsen commented Jan 8, 2013

@bnoordhuis should this land i master or v0.8?

Member

piscisaureus commented Jan 8, 2013

@AndreasMadsen

API change -> master

bmeck commented Jan 11, 2013

@AndreasMadsen all of this fixed with your pr?

Member

AndreasMadsen commented Jan 11, 2013

Yes

Member

piscisaureus commented Jan 11, 2013

Fixed in 6a91eab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment