-
Notifications
You must be signed in to change notification settings - Fork 17.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
proposal: io/fs: return ErrInvalid if the pattern argument of Glob is not a valid path #44092
Comments
I think it would also be reasonable to instead return |
I am not at all sure we should make any change here.
The directory "/" does not exist in an FS; that's why "/*" doesn't have any matches. As another analogy, if we are running on a file system without support for Unicode,
filepath.Glob returns no matches and no error for this too.
I am more sympathetic to this example than /a, but not enough to make an exception. In the first two examples the behavior seems clearly correct (given the non-existence of / and the current behavior of filepath.Glob). That leaves only the third, but a special case would add more complexity about interpreting error results and deviate from the other two. |
@rsc Thanks, I get your point and I'm fine to close this issue. Perhaps a note in the documentation could help to better understand this behavior, which after your exposition I believe correct. |
No change in consensus, so declined. |
If
pattern
is a well-formed pattern but it does not satisfyfs.ValidPath(pattern)
,fs.Glob(fsys, pattern)
does not return matchings and does not return errors.For example, if
fs.Glob(fsys, "a")
returns[]string{"a"}
andnil
, these other callsreturn
nil
andnil
:I propose, before the 1.16 release, that the
fs.Glob
function returns thefs.ErrInvalid
error ifpattern
is a well-formed pattern but does not satisfyfs.ValidPath
instead of returning anil
matched and anil
error.Note that the
filepath.Glob
function, asfs.Glob
, can return only thepath.ErrBadPattern
error butfilepath.Glob
cleans the pattern before matching the files,fs.Glob
doesn't.Note also that
//go:embed
has the same pattern syntax offs.Glob
(except ".") butdoes not compile if
pattern
does not satisfyfs.ValidPath
, instead of assigning tofiles
an empty file system.The text was updated successfully, but these errors were encountered: