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: implement %b for printf builtin #955

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

reubeno
Copy link
Contributor

@reubeno reubeno commented Dec 7, 2022

Update printf implementation to do the same as echo -e for the %b format specifier: expand backslash escape sequences in the provided argument but not % format specifiers.

Extracts inner logic from Format into formatIntoBuffer to avoid issues with non-reentrancy of Format (due to use of a special cached buffer in Config.


Request for feedback

This was the simplest change that I could see, but I wasn't thrilled about having formatIntoBuffer recursively call itself for the %b case; this shouldn't generally be problematic, since the recursive call won't process % format specifiers and shouldn't further recur.

@reubeno reubeno changed the title interp: implement %b for print builtin interp: implement %b for printf builtin Dec 7, 2022
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.

Thanks! Two thoughts below.

I'm not too worried about the recursion. We can always optimize or refactor later if needed.

Update printf implementation to do the same as 'echo -e' for
the %b format specifier handled by bash: expand backslash
escape sequences in the provided argument but not % format
specifiers.
@mvdan mvdan merged commit b01c433 into mvdan:master Dec 7, 2022
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