Special characters not being escaped on `system` call
ernestorocha opened this issue · 2 comments
When running the command gpt
and on the input prompt the phrase has some special character, for instance '
, it breaks the system
call of the plugin.
For example:
This is caused by how the system
call is made here https://github.com/0xStabby/chatgpt-vim/blob/master/plugin/chatgpt.vim#L10
So, we should escape the input string with shellescape
, like this:
let prompt = shellescape(input("Enter chatgpt prompt: "))
as described here: https://github.com/airblade/vim-system-escape/blob/master/README.md
And remove the single quote from system
call:
Previous code:
let output = system("echo '" . prompt . "' | openai complete - -t " . g:openaiToken)
New code:
let output = system("echo " . prompt . " | openai complete - -t " . g:openaiToken)
So we can perform queries with special characters:
PS: Great plugin by the way! :)
Oh awesome! Thanks for the fix! This is an issue I was aware of but had not gotten around to figuring out a solution.
If you would like you can feel free to fork the repo and create a pull request with this update, I will pull it in. If not then I'll just throw the fix in myself.
And thanks, glad you like it!
Added, thanks again for the tip!