public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: [bug] globify dospath reacts poorly with escaped double quotes
@ 2019-10-10  8:30 Mingye Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Mingye Wang @ 2019-10-10  8:30 UTC (permalink / raw)
  To: cygwin

On Tue, 8 Oct 2019 14:09:18 -0600, Brian Inglis wrote:

> Msys2 tools have to make their own arrangements if they support native Windows
> paths.
> Personally I found when I used to use DOS and Windows tools, it was easier using
> slashes instead of backslashes as directory separators, as most interfaces did
> not care, including most DOS & Windows APIs.

Use the source, Luke. Globbing on the cmdline, as we all know, is
something you only
care about when you are *not* passing in arguments from a Unix-type cmdline, and
build_argv in dcrt0.cc does *only* run globify if the parent process is *not*
Cygwin-powered.

> Backslash escaping and switching enclosing quotes on shell command lines...

See above.

--
Mingye Wang (Artoria2e5)

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread
* [bug] globify dospath reacts poorly with escaped double quotes
@ 2019-10-08  9:05 Mingye Wang
  2019-10-08 20:09 ` Brian Inglis
  2019-10-10 13:13 ` Ken Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Mingye Wang @ 2019-10-08  9:05 UTC (permalink / raw)
  To: cygwin

Hi,

This bug is inherited from early versions of Cygwin. It's so old that
MSYS2 has this problem too.

There is no way of conveying a double quote in an argument once
globify() decides it has seen a dospath. Neither the `\"` nor `""`
work, because they are both unified to `\"` in quoted() and turned
into a `\\` pattern in globify().

This is problematic for programmers trying to write a routine to
reliably escape an argument for the Cygwin command-line.

A way to patch the problem is with a lookahead in globify():

if (dos_spec && *s == '\\') {
/**/p++ = '\\';
/**/if (s[1] == '"' && s[2]) {
/****/*p = *++s;
/****/continue;
/**/}
}
*p = *s;

[Apologies for the formatting; the gmail web editor hates leading spaces.]

(Note: The backslash thing has always been different from the MSCRT
handling, which only transforms backslashes followed by a double
quote. But this is fine as long as we are internally consistent.
Well... is it documented anywhere?)

--
Regards,
Mingye Wang

--
Mingye Wang (Artoria2e5)

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-10 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10  8:30 [bug] globify dospath reacts poorly with escaped double quotes Mingye Wang
  -- strict thread matches above, loose matches on Subject: below --
2019-10-08  9:05 Mingye Wang
2019-10-08 20:09 ` Brian Inglis
2019-10-10 16:37   ` Brian Inglis
2019-10-10 13:13 ` Ken Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).