d0vgan / nppexec

NppExec (plugin for Notepad++)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How escaping works inside NppExec?

badrelmers opened this issue · comments

Hi
First I want to thank you for this excellent tool.
I m having some difficulties to understand how escaping works inside NppExec, and the manual and internet did not help me.
After a lot of testing I come to some conclusions which I hope you can confirm or correct please.

  • does NppExec do some procesing to the commands we send like it always happens with cmd and bash?
  • what is the correct way to escape inside NppExec? for example how to escape double quotes " ? do I need to use the quoting of cmd which is doubling the double quotes "" ? or it is \" the correct way?
  • why escaping with double double quotes "" works? does nppexec pass the commands to cmd silently?

here are the tests I did and the conclusion: it is long sorry for this!

use "..." not '...'

this works:

npp_run mintty -h always /bin/bash -c ' echo " I'\''m " '

but this fails:

npp_run mintty -h always /bin/bash -c " echo ' I'\''m ' "

conclusion:

so I have to pass commands inside double quotes "..." not single quotes '...'
so nppexec do some processing to the commands we send?


A more advanced case

how to escape " inside "...": \" or "" ?

case1:

inside nppexec \" works

npp_run mintty -h always /bin/bash -c "trap 'echo \"&trappp ; ddd\" ' exit ; echo 'fff' "

and also "" works

npp_run mintty -h always /bin/bash -c "trap 'echo ""&trappp ; ddd"" ' exit ; echo 'fff' "

case2: run all inside cmd /C

if i pass \" to cmd then it fails because of cmd processing of course

npp_run cmd /C mintty -h always /bin/bash -c "trap 'echo \"&trappp ; ddd\" ' exit ; echo 'fff' "

but works if i pass "" to cmd which is expected

npp_run cmd /C mintty -h always /bin/bash -c "trap 'echo ""&trappp ; ddd"" ' exit ; echo 'fff' "

case3: pass a single quote '

works fine

npp_run mintty -h always /bin/bash -c "trap 'echo \"&trappp _quote'\''_ ; ddd\" ' exit ; echo 'fff' "

works fine

npp_run mintty -h always /bin/bash -c "trap 'echo ""&trappp _quote'\''_ ; ddd"" ' exit ; echo 'fff' "

fails

npp_run cmd /C mintty -h always /bin/bash -c "trap 'echo \"&trappp _quote'\''_ ; ddd\" ' exit ; echo 'fff' "

works fine

npp_run cmd /C mintty -h always /bin/bash -c "trap 'echo ""&trappp _quote'\''_ ; ddd"" ' exit ; echo 'fff' "

conclusion:

it is clear that "" works always
should i consider it the right way to escape inside nppexec?


maybe it is hard to read above examples so I include the same as a screenshot with colors:
image


image

Thank you very much

NppExec does not support escaping in strings, however it supports the following pairs of quotes:

"abc"
'abc'
`abc`

This allows to embed different quote characters into another pair of quotes. For example:

`Here's an example of "embedded" quote characters`

Yes I already saw that in the manual, but it seems to work only when defining a variable, I don't know how to use it to pass commands to npp_run. Those quotes are not even removed when I use them with npp_run:

npp_run mintty -h always bash -c `echo fff`

image

am I missing something? thank you

The command line under NPP_RUN is directly passed to the system. NppExec does not perform any conversion for this command.
As help npp_run explains, it is "The same as Notepad++'s Run command - runs an external process". And the provided examples use double-quotes.
If you need to pass double-quotes within command line arguments which are already surrounded with outer double quotes, you should follow the escaping rules of Windows' command interpreter (cmd.exe) itself, it has nothing to do with NppExec processing. For example:

npp_run cmd /K gawk -f "BEGIN { print \"\" }"

NppExec is not involved in processing of quotes in "BEGIN { print \"\" }", they are just passed as is, and all the magic with them is done by cmd.exe.

you should follow the escaping rules of Windows' command interpreter (cmd.exe) itself

this is what I was looking for, this explains all
thank you very much