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

Escape filePath and args passed to the phpcs command #145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aslamdoctor
Copy link

@aslamdoctor aslamdoctor commented Sep 26, 2024

Fixes issue #144

Tested on Mac.
Need to be tested on Windows.

@jonathanbossenger
Copy link
Collaborator

@aslamdoctor thanks for the PR. Of course, both the filePath and the standard would need to be escaped if they're both in the same location 🤦 I'm annoyed I missed that 😁

One question: in my original PR, to fix for just the filePath, instead of running the string through a string replace, I wrap the string in double quotes. This comes from my experiences in bash scripting, where one should wrap any variables in double quotes, to prevent scripts from breaking when input contains spaces, line feeds, glob characters and such.

I will freely admit I don't know a lot about the node child_process spawn method used to execute the phpcs command, but it seems to me that following the same process for escaping strings in the terminal made sense here. However, as it's a JavaScript code calling a method to execute the command, perhaps your solution is the better option.

Do you have any opinions on this?

@valeryan, as the original developer, I'd also appreciate any thoughts you might have on which solution is "better"; thanks.

@valeryan
Copy link
Owner

valeryan commented Oct 2, 2024

Seems like a good solution. Makes me wish I had time to write unit test though...

@aslamdoctor
Copy link
Author

@jonathanbossenger I was also confused why adding the double quote didn't work. It was supposed to work. It's quiet tedious to debug this. But I believe when you pass anything as argument to a command on terminal, it shouldn't have space and needs to be escaped with \.

@jonathanbossenger
Copy link
Collaborator

Ok, thanks for the confirming folks, let's go ahead and get this merged.

@jonathanbossenger
Copy link
Collaborator

Makes me wish I had time to write unit test though...

@valeryan I hear you, but in my experience open source tools often don't get tests until someone comes along with enough time to add them. I will see if I can put some time aside for this as well.

@jonathanbossenger
Copy link
Collaborator

Need to be tested on Windows.

I can test this on Windows, hopefully tomorrow.

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.

3 participants