[BUG] T-REPLACE-RX adding extra quotation marks

eric1024
2014-05-10
2014-05-10
  • eric1024
    eric1024
    2014-05-10

    I'm trying to come up with a solution to a problem I'm having (https://sourceforge.net/p/keepass/discussion/329220/thread/1dcd2363/) and am trying to use the T-REPLACE-RX function inside of the Custom Scheme Override.

    My URL for the database entry is as follows (note: quotes around path and executable are necessary due to spaces in program files path):

    putty://"{ENV_PROGRAMFILES_X86}\PuTTY\putty.exe" {USERNAME}@{s:Server}

    I created the scheme override called putty and used the following:

    cmd://{T-REPLACE-RX:!{URL:RMVSCM}!C:\Program.*(PuTTY\putty.exe)!D:\$1!}

    This should be replacing this:

    C:\Program Files (x86)\PuTTY\putty.exe with

    with this:

    D:\putty.exe

    So, the final URL should become:

    cmd://"D:\PuTTY\putty.exe" {USERNAME}@{s:Server}

    However, there seem to be extra spaces being added in somehow. This is the error I get when I try to launch the URL:


    File/URL:
    Arguments: "D:\PuTTY\putty.exe""" testuser@testserver
    Cannot start process because a file name has not been provided.


    Notice there are three quotation marks after the putty.exe and one before the D.

    Those extra " symbols are causing the command to be incorrect.

    Also, I initially tried to search for {ENV_PROGRAMFILES_X86} as a whole and replace it with D:\ but that failed. I received this error:


    File/URL:
    Cannot start process because a file name has not been provided.


    I'm not sure if this is because this placeholder cannot be used inside of the T-REPLACE-RX function, or if it's because there are single \ characters inside of it.

     
  • Dominik Reichl
    Dominik Reichl
    2014-05-10

    This behavior is intended; it's required to correctly encode quotes when {T-REPLACE-RX:...} is used within the parameters of the command line instead of the file.

    You could use the following override for putty://:
    cmd://{T-REPLACE-RX:!{URL:RMVSCM}!"+[^"]+"+!D:\PuTTY\putty.exe!}

    Anyway, I think it would be better to not put the PuTTY path into the URL of the entry and instead specify it in the override only. KeePass contains a built-in override for ssh://, where the override looks like cmd://PuTTY.exe -ssh {USERNAME}@{URL:RMVSCM}. You could create something similar for putty://, specifying the full path to the executable file.

    Best regards,
    Dominik