fix: Error passing arguments to chblade-exec-os. #708
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Super-long 0x4f4f4f4f@gmail.com
Describe what this PR does / why we need it
When the following statement is executed, the data in /tmp/abc will be truncated:
The cause of the problem is that strings.Split in chaosblade/exec/os/executor.go will truncate "HELL WORLD'" to "HELL" and "WORLD", that is, there are two data in argsArray, then chaosblade-exec- os will incorrectly parse --content as "HELL".
We need to make "HELL WORLD" parse to one item in argsArray.
This bug will make the parsing of all parameters with spaces fail, such as filename, content, etc.
At the same time, I found that #46 has something to do with this bug. In chaos-exec-os, the uid failed to be resolved.
Does this pull request fix one issue?
Fixes #707 and part of #46
Describe how you did it
I made all flags resolve to one item in argsArray and fixed the uid bug.
Now when executing os_exec.CommandContext the argsArray looks like this:
it used to be like this:
Describe how to verify it
Executing statements in #707 is now expected behavior.
Special notes for reviews
On the question of whether to add an equals sign on line 64. I try to modify the statement to 'flags = fmt.Sprintf("--%s %s", k, v)', after executing 'dlv exec ./chaos_os -- 'create' 'file' 'append' '--filepath /tmp/abc' '--content HELL WORLD' '-uid 54c63e1814e9c126' get the following results:
'''