-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
expand: parameter expansions with spaces in the middle of words are mishandled #886
Comments
The problem can be reproduced with this unit test case in interp/interp_test.go: |
Not all expansions have the problem -- only unquoted ones that aren't on the right hand side of an assignment?
|
Shortest repro, perhaps:
|
So this rescues that one test case:
It also breaks lots of other stuff. |
Your original bug report is valid - you correctly show that our interpreter prints something different than Bash. That does sound like a bug. However, note that your second reproducer is invalid, as currently our interpreter outputs the same as Bash - note the lack of leading or trailing whitespace:
I believe the bug exists when an unquoted parameter expansion exists in the middle of a word, like |
I wouldn't call it an attempted fix, more like a depth charge :-) |
That is: $ a=" b c " $ echo foo${a}bar foo b c bar rather than our previous incorrect answer: $ a=" b c " $ echo foo${a}bar foob cbar Our error was relying on strings.FieldsFunc, which performs exactly as documented, but is not enough for us - we need to know whether the expanded string has leading or trailing IFS characters. Fixes #886.
That is: $ a=" b c " $ echo foo${a}bar foo b c bar rather than our previous incorrect answer: $ a=" b c " $ echo foo${a}bar foob cbar Our error was relying on strings.FieldsFunc, which performs exactly as documented, but is not enough for us - we need to know whether the expanded string has leading or trailing IFS characters. Fixes #886.
It feels like gosh trims leading and trailing spaces from variables:
I would have expected gosh x.sh and sh x.sh to produce identical output, but gosh outputs "aQb" while sh outputs "a Q b".
Looks like the variable has the spaces, but they are trimmed during variable expansion?
The text was updated successfully, but these errors were encountered: