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

Literal brace expansion is buggy #9351

Open
mqudsi opened this issue Nov 13, 2022 · 7 comments
Open

Literal brace expansion is buggy #9351

mqudsi opened this issue Nov 13, 2022 · 7 comments
Labels
bug Something that's not working as intended

Comments

@mqudsi
Copy link
Contributor

mqudsi commented Nov 13, 2022

A while ago, a patch was added when it was observed that the majority of cases involving {} were accidental and intended the literal braces to be printed/evaluated rather than invoking cartesian expansion. This was then also expanded to consider {x} where x is anything that doesn't contain an unescaped , to also be taken as a literal expression and not enter a special parsing mode.

I've recently discovered that this isn't done quite right and that whitespace within {} braces is emitted literally as if escaped rather than coalesced:

> printf "'%s'\n" {      }
'{      }'

I don't believe this is intentional, and even if it were, I believe it shouldn't be parsed as such. Treating { and } as literal tokens at the parser level is fine, but we don't have any concepts of literal whitespace except when individually prefixed with \ or when in a quoted context. It also goes against how brace expansion handles whitespace in general:

> printf "'%s'\n" { hello , world }
'hello'
'world'

It's ok to treat {one} as a single, literal token but IMHO { one } should be treated as three separate tokens.

@mqudsi mqudsi added the bug Something that's not working as intended label Nov 13, 2022
@faho

This comment was marked as outdated.

@faho faho closed this as completed Nov 14, 2022
@faho faho added duplicate and removed bug Something that's not working as intended labels Nov 14, 2022
@mqudsi

This comment was marked as outdated.

@mqudsi mqudsi reopened this Nov 15, 2022
@floam floam added bug Something that's not working as intended and removed duplicate labels Nov 15, 2022
@mqudsi
Copy link
Contributor Author

mqudsi commented Nov 16, 2022

The behavior was introduced in #6565, which was a patch that we knew broke some things but punted on fixing them until after the 3.1 release. For what it is worth, it seems that at least some of the behavior we all agreed is buggy or out-of-spec was intentional at the time the PR was drafted, though in the comments everyone seems to mostly agree that it's wrong and should be changed.

@krobelus
Copy link
Member

Thanks for linking the previous discussion. The gist is

Braces are now equivalent to a new form of quoting, except the quote is preserved and emitted in the output.

so at least for matching braces without an enclosed comma, we should probably remove the special treatment

@mqudsi
Copy link
Contributor Author

mqudsi commented Nov 17, 2022

After reading the previous issues, I no longer know what is the desired behavior here. (I know what I would like, but that's not the same question.)

@ChristoferK

This comment was marked as resolved.

@faho

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

5 participants