-
Notifications
You must be signed in to change notification settings - Fork 165
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
[#1657] Escape special chars for bash commands #1662
[#1657] Escape special chars for bash commands #1662
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is trivial but maybe we can cover the case on that line. Otherwise LGTM.
*/ | ||
public static String addQuotesForFilePath(String filePath) { | ||
if (SystemUtil.isWindows()) { | ||
return "\"" + filePath + "\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to cover this line in the test as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I don't think there is a good way to test the escaping specifically. We can add a test case just to check if quotation marks are added which does not seem very useful. For this case, it was to avoid mishandling of spaces in the repo directory and the test cases are located here.
For testing the escaping specifically, I don't think there's a good way to test this for Windows filesystems. The CMD's echo
command echoes the quotation marks compared to bash's echo
command which strips the quotation marks and does symbol substitution where appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this line missed just because the coverage report wasn't generated on Windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's more that there isn't a specific test case that runs this line of code at all since the test case I added only runs on non-Windows systems.
/** | ||
* Adds the appropriate quotation marks for a file path depending on the OS. | ||
*/ | ||
public static String addQuotesForFilePath(String filePath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be possible that developers forget to use these if they weren't sure how or when to use them. Do you think it would be a good idea now to create a CommandBuilder to take care of these things?
This could be tricky though, given that the construction of commands can be non-trivial so this might be out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I actually voiced a similar idea here and you can read the response from dcshzj but besides adding paths, most other argument types are quite tailored to the specific git command. So this is a specific standard for file paths only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link! It's interesting seeing similar discussions and considerations springing up independently at different points in this project :)
…m:chan-j-d/RepoSense into 1657-escape-special-chars-in-bash-command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@dcshzj @fzdy1914 would it be possible to get a final review sooner or merge it earlier? I think the |
I will move this PR along since it is necessary for some of the other PRs. |
The following links are for previewing this pull request:
|
Fixes #1657
Currently, the file path arguments are added to
git
commands using normal double quotes. However, for Bash terminals, double quotes still allow for special symbols like$
to perform a special function like referencing a variable name. There is a need to use single quotes for Bash terminals. Single quotes'
themselves are escaped as such'"'"'
by breaking up the string into various quoted segments where a single quote is left in a double quoted segment as per this stackoverflow post.The test case specifically tests against special bash characters according to this unix stackexchange post.
Unfortunately, Windows CMD does not work with single quotes and only accepts double quotes. As such, there needs to be a distinction in the way this is done for different OS.
A small note was added to the DG of the importance in using this additional method.
Commit message: