Thread: psql's EDITOR behavior on Windows

psql's EDITOR behavior on Windows

From
Pavlo Golub
Date:
Hello.

I cannot find the reason why EDITOR value on Windows is quoted. It
should not be. One may force quote env var if he wants to.

Right now, for example, one cannot use sublime, since to use it in a
proper way you should
SET EDITOR="C:\Program Files\Sublime\subl.exe" --wait

The problem can be solved by introducing PSQL_EDITOR_ARGS env var, but
just not quoting EDITOR command on Windows will work too.

psql\command.c:

static bool
editFile(const char *fname, int lineno)
{
    ...

        /*
     * On Unix the EDITOR value should *not* be quoted, since it might include
     * switches, eg, EDITOR="pico -t"; it's up to the user to put quotes in it
     * if necessary.  But this policy is not very workable on Windows, due to
     * severe brain damage in their command shell plus the fact that standard
     * program paths include spaces.
     */
    ...
    if (lineno > 0)
        sys = psprintf("\"%s\" %s%d \"%s\"",
                       editorName, editor_lineno_arg, lineno, fname);
    else
        sys = psprintf("\"%s\" \"%s\"",
                       editorName, fname);
    ...
}



Re: psql's EDITOR behavior on Windows

From
Tom Lane
Date:
Pavlo Golub <pavlo.golub@cybertec.at> writes:
> I cannot find the reason why EDITOR value on Windows is quoted.

The comment you quoted explains it: apparently people expect
paths-with-spaces to work in that value without any manual quoting.

> One may force quote env var if he wants to.

Given the lack of prior complaints, I'm not sure we should change
this to support an editor that can't be made to work without special
command line switches.  We're likely to make more people unhappy
than happy ... especially if it's then impossible to set the variable
so that it works with both older and newer psql's.

            regards, tom lane



Re: psql's EDITOR behavior on Windows

From
Tom Lane
Date:
I wrote:
> Pavlo Golub <pavlo.golub@cybertec.at> writes:
>> I cannot find the reason why EDITOR value on Windows is quoted.

> The comment you quoted explains it: apparently people expect
> paths-with-spaces to work in that value without any manual quoting.

Actually, after digging in the git history and archives, the current
behavior seems to trace back to a discussion on pgsql-hackers on
2004-11-15.  The thread linkage in the archives seems rather incomplete,
but it boiled down to this:

https://www.postgresql.org/message-id/9045.1100539151%40sss.pgh.pa.us

ie, the argument that people could handle space-containing paths by
putting double quotes into the environment variable's value is just wrong.
Possibly Microsoft fixed that in the fifteen years since, but I'd want to
see some proof.

            regards, tom lane



Re: psql's EDITOR behavior on Windows

From
Pavlo Golub
Date:
On Wed, Dec 18, 2019 at 4:11 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>
> I wrote:
> > Pavlo Golub <pavlo.golub@cybertec.at> writes:
> >> I cannot find the reason why EDITOR value on Windows is quoted.
>
> > The comment you quoted explains it: apparently people expect
> > paths-with-spaces to work in that value without any manual quoting.
>
> Actually, after digging in the git history and archives, the current
> behavior seems to trace back to a discussion on pgsql-hackers on
> 2004-11-15.  The thread linkage in the archives seems rather incomplete,
> but it boiled down to this:
>
> https://www.postgresql.org/message-id/9045.1100539151%40sss.pgh.pa.us
>
> ie, the argument that people could handle space-containing paths by
> putting double quotes into the environment variable's value is just wrong.
> Possibly Microsoft fixed that in the fifteen years since, but I'd want to
> see some proof.

Interesting. Thanks. I'll prepare a patch showing the case.

>
>                         regards, tom lane