Bug 10278 - glob() gives inconsistent results with trailing "/"
: glob() gives inconsistent results with trailing "/"
Status: NEW
Product: glibc
Classification: Unclassified
Component: libc
: 2.8
: P2 normal
: ---
Assigned To: Not yet assigned to anyone
:
:
:
:
  Show dependency treegraph
 
Reported: 2009-06-13 21:56 UTC by psmith
Modified: 2012-12-19 10:49 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description psmith 2009-06-13 21:56:25 UTC
The POSIX spec doesn't specify exactly what should happen with a pattern ending
in "/"; all it says about slashes in patterns is:

The slash character in a pathname shall be explicitly matched by using one or
more slashes in the pattern; it shall neither be matched by the asterisk or
question-mark special characters nor by a bracket expression.

All shells I'm aware of interpret this to mean that if your glob expression ends
with a "/", it should match only directories.  GNU glob() handles this correctly
for simple globbing expressions like "*/", but for other expressions like
"dir/*/", "/*/", etc. it returns all directories with a trailing slash, AND all
files without a trailing slash.

I believe this inconsistent behavior is a bug.

See also GNU make bug #18123 http://savannah.gnu.org/bugs/index.php?18123
Comment 1 Eric Blake 2012-03-04 13:34:14 UTC
The rest of POSIX is pretty clear that pathname resolution of a name with a
trailing slash can only succeed if it matches a directory; this is definitely a
bug in glob().