Skip to content
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

interp: Return invalid globs when nullglob is set #862

Merged
merged 1 commit into from
May 19, 2022

Conversation

lollipopman
Copy link
Contributor

Prior to this commit invalid globs were returned as null when nullglob
was set, which resulted in test expressions failing:

$ shopt -s nullglob; [ -n butter ] && echo bubbles
"-n": executable file not found in $PATH

After this commit invalid globs are returned verbatim when nullglob is
set.

@mvdan
Copy link
Owner

mvdan commented May 18, 2022

I'm a bit confused by your commit message: butter is not an invalid glob, as far as I can tell.

@lollipopman
Copy link
Contributor Author

I'm a bit confused by your commit message: butter is not an invalid glob, as far as I can tell.

Sorry, I didn't mean to make the example confusing, the invalid glob is the first opening of the test expression, [, on master when running the example in gosh, you get:

$ shopt -s nullglob; [ -n butter ] && echo bubbles
"-n": executable file not found in $PATH

because with nullglob enabled the current code does not append the invalid glob, so the opening bracket is removed from the expression.

@mvdan
Copy link
Owner

mvdan commented May 18, 2022

Ah, I see, thanks for the clarification.

Do we need to add InvalidGlobError? It's the only error that the method ever returns, so we can avoid extending the API and simply use err != nil in the caller to tell whether the glob is valid or not.

Otherwise the change sounds good to me!

@mvdan
Copy link
Owner

mvdan commented May 18, 2022

Err, scratch that. I hadn't noticed that the call is to the glob method, which then indirectly calls pattern.Regexp. We do need to differentiate the error. So I think what you've done is good.

@lollipopman
Copy link
Contributor Author

Err, scratch that. I hadn't noticed that the call is to the glob method, which then indirectly calls pattern.Regexp. We do need to differentiate the error. So I think what you've done is good.

I also considered having the glob function return nil, nil when the glob is invalid and then having the caller differentiate between a nil slice and an empty slice. That method worked, but it seemed a little too clever and brittle.

@mvdan
Copy link
Owner

mvdan commented May 19, 2022

Yeah, I agree that's too subtle - I don't like APIs that give different meanings to nil vs empty.

Copy link
Owner

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM with a naming nit

pattern/pattern.go Outdated Show resolved Hide resolved
Prior to this commit invalid globs were returned as null when nullglob
was set, which resulted in test expressions failing:

  $ shopt -s nullglob; [ -n butter ] && echo bubbles
  "-n": executable file not found in $PATH

After this commit invalid globs are returned verbatim when nullglob is
set.
@lollipopman
Copy link
Contributor Author

Thanks for the careful review @mvdan, I believe this is now ready to merge.

@mvdan mvdan merged commit c0abc06 into mvdan:master May 19, 2022
@mvdan
Copy link
Owner

mvdan commented May 19, 2022

Thanks to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants