Bug 436374 - KDE Connect run command plugin on windows problems with quotes
Summary: KDE Connect run command plugin on windows problems with quotes
Status: RESOLVED FIXED
Alias: None
Product: kdeconnect
Classification: Applications
Component: common (other bugs)
Version First Reported In: unspecified
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Albert Vaca Cintora
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-29 20:24 UTC by bijaf45294
Modified: 2021-05-26 05:24 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bijaf45294 2021-04-29 20:24:06 UTC
SUMMARY

I'm not sure exactly how broken this is, but when i try to run a command with quotes in it (parameters with spaces) the command doesn't run successfuly.

I tried running nircmd.exe (https://www.nirsoft.net/utils/nircmd.html) program to speak text with parameters:
nircmd.exe speak text "Hello world asd asd" 2

the command expects [speak] [text] [Text to speak] [speak rate] [volume]
but the computer spoke
Backslash Hello world asd asd Backslash

So it somehow understands that the text i put between the quotes is just one argument (it doesn't overwrite speak rate and volume), but it adds backslashes somewhere.
I tried editing the config file in the AppData folder and removing some backslashes there, but it deleted all of my commands.
I also tried looking at the source code, but I don't understand much C++

For writing this report, I created a simple executable that just writes its arguments to a file, with the following C# code:
public class a{
    public static void Main(string[] args){
        File.AppendAllText("D:\\args.txt", args.Length.ToString() + " Values:\r\n");
        for(int i=0; i<args.Length; i++){
            File.AppendAllText("D:\\args.txt", args[i]);
            File.AppendAllText("D:\\args.txt", "\r\n");
}}}

And now that program says it gets 7 arguments when i run with the same commands. (It doesn't accept quoted string as a single command, while if i run it from command line, it does.)
It says the third argument starts with a quote and sixth one ends with a quote.



STEPS TO REPRODUCE

1. Be on Windows
2. Create a Command that uses quotes in the command
3. Watch it break in different ways


OBSERVED RESULT

While the nircmd.exe program gets the argument with additional backslashes, my test program gets each word in the arguments seperately.


EXPECTED RESULT

Both of the commands to work like executing with them with cmd /k as runplugincommand.cpp tries to do


SOFTWARE/OS VERSIONS

Windows: Windows 10 1909 - Kde connect 1.4-573
Android: 1.16


ADDITIONAL INFORMATION
Comment 1 brute4s99 2021-05-08 23:52:40 UTC
Thanks for reporting the bug.
I just pushed a patch to fix this. It's available at https://invent.kde.org/network/kdeconnect-kde/commit/3b7d51dc804a075af7eef26f9b415f05187c66b4


The nightly build doesn't work right now, but if you want to test if it works fine for you now, go ahead and install the package made on my machine hosted here : https://baadal.my.to/s/BPBZ6NRNig9HrQR  
Alternatively, ping me on @PiyushAggarwal on Telegram. I'll keep you in the loop and let you know when the nightly is good again.
Comment 2 bijaf45294 2021-05-25 20:41:06 UTC
Thanks for the patch! Looks like it works great.
In the past I couldn't get it to work with specifying an absolute executable path, but now that works too.
Comment 3 brute4s99 2021-05-26 05:24:52 UTC
Awesome!
PS: the nightly is well again!