rusty-hook icon indicating copy to clipboard operation
rusty-hook copied to clipboard

Hooks are not unescaping Quotes before executing

Open comods opened this issue 4 years ago • 8 comments

Environment Details

  • Operating System
    • Windows
  • Rust Version: 1.43.0
  • Rust Release Channel
    • Stable
  • Cargo Version: 1.43.0
  • rusty-hook Version: 0.11.1

Description

These fail but shouldn't:

pre-commit = "\"echo\"" pre-commit = """("echo")"""

Being unable to use quotes is preventing me from using pre-commit = """(git status --short | grep -q "^...folder/")""" in my logic to only compile when changes are made in my rust folder.

comods avatar Apr 26 '20 05:04 comods

"\"echo\"" is ran as \"echo\" but should be ran as "echo". """("echo")""" is ran as (\"echo\") but should be ran as ("echo").

comods avatar Apr 26 '20 05:04 comods

Thanks for the report @RefinedSoftwareLLC! Will try to take a deeper look at this one tomorrow

calebcartwright avatar Apr 26 '20 05:04 calebcartwright

As a workaround, I got grep to work by removing all quotes and escape backslashes. """(grep -q "^...folder\.com/")""" for now has to be """(grep -q ^...folder.com/)"""

  • apparently I don't need quotes around the regexp.
  • but \. doesn't work so I have to use . which matches all characters instead of only a period.
  • using \\. in grep regexp just hangs the commit and it never stops running.

comods avatar Apr 26 '20 06:04 comods

I can't reproduce this on Linux, but will check on my Windows machine in a bit.

Could you share two additional things whenever you get a chance?

  1. The output of rusty-hook --version (this will likely be 0.11.1 too but just want to check)
  2. The output of the git command (presumably commit) that you mentioned is failing with those hook scripts
$ git commit -m "foo"
Found configured hook: pre-commit
Running command: ("echo")

[master d9d19f2] foo
 1 file changed, 1 insertion(+), 1 deletion(-)

calebcartwright avatar Apr 27 '20 00:04 calebcartwright

Yes, version 0.11.1

Found configured hook: pre-commit
Running command: ("echo")
'\"echo\"' is not recognized as an internal or external command,
operable program or batch file.

In cmd, if you directly type (\"echo\") you get the same error, but ("echo") works.

comods avatar Apr 27 '20 18:04 comods

I'm guessing the escaping is due to https://github.com/rust-lang/rust/issues/29494

calebcartwright avatar Apr 29 '20 03:04 calebcartwright

As this issue is unlikely to be fixed upstream (judging by the time it has been open for) can we fix this by using a different way of executing these commands? Afaict there is some workaround by using CreateProcessW but I haven't looked too much into it. Is this something that's affecting a lot of users?

Mastermindaxe avatar Feb 01 '21 20:02 Mastermindaxe

can we fix this by using a different way of executing these commands? Afaict there is some workaround by using CreateProcessW but I haven't looked too much into it. Is this something that's affecting a lot of users?

No, there's several viable, if mildly annoying, workarounds that are readily available, and we're definitely not going to dip down to CreateProcessW directly. Folks can use the workarounds for now (even if that means defining the script in a file that's then invoked from the hook script) and we'll update accordingly whenever things are patched upstream

calebcartwright avatar Feb 10 '21 03:02 calebcartwright