All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harald van Dijk <harald@gigawatt.nl>
To: Denys Vlasenko <vda.linux@googlemail.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	dash@vger.kernel.org
Subject: Re: dash bug: double-quoted "\" breaks glob protection for next char
Date: Wed, 14 Feb 2018 22:44:09 +0100	[thread overview]
Message-ID: <297b41c4-0e15-e0d8-f088-d68acfcc3c0f@gigawatt.nl> (raw)
In-Reply-To: <5e1ee06d-d1ca-6442-51de-786e2739d4df@gigawatt.nl>

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

On 2/14/18 9:03 PM, Harald van Dijk wrote:
> On 13/02/2018 14:53, Denys Vlasenko wrote:
>> $ >'\zzzz'
>> $ >'\wwww'
>> $ dash -c 'echo "\*"'
>> \wwww \zzzz
> 
>[...]
> 
> Currently:
> 
> $ dash -c 'foo=a; echo "<${foo#[a\]]}>"'
> <>
> 
> This is what I expect, and also what bash, ksh and posh do.
> 
> With your patch:
> 
> $ dash -c 'foo=a; echo "<${foo#[a\]]}>"'
> <a>

Does the attached look right as an alternative? It treats a quoted 
backslash the same way as if it were preceded by CTLESC in _rmescapes. 
It passes your test case and mine, but I'll do more extensive testing.

Cheers,
Harald van Dijk

[-- Attachment #2: dash-escape-backslash.patch --]
[-- Type: text/x-patch, Size: 585 bytes --]

diff --git a/src/expand.c b/src/expand.c
index 2a50830..af88a69 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1686,12 +1686,17 @@ _rmescapes(char *str, int flag)
 		}
 		if (*p == (char)CTLESC) {
 			p++;
-			if (notescaped)
-				*q++ = '\\';
-		} else if (*p == '\\' && !inquotes) {
-			/* naked back slash */
-			notescaped = 0;
-			goto copy;
+			goto escape;
+		} else if (*p == '\\') {
+			if (inquotes) {
+escape:
+				if (notescaped)
+					*q++ = '\\';
+			} else {
+				/* naked back slash */
+				notescaped = 0;
+				goto copy;
+			}
 		}
 		notescaped = globbing;
 copy:

  reply	other threads:[~2018-02-14 21:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 13:53 dash bug: double-quoted "\" breaks glob protection for next char Denys Vlasenko
2018-02-13 22:45 ` Martijn Dekker
2018-02-14 20:03 ` Harald van Dijk
2018-02-14 21:44   ` Harald van Dijk [this message]
2018-02-14 22:50     ` Harald van Dijk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=297b41c4-0e15-e0d8-f088-d68acfcc3c0f@gigawatt.nl \
    --to=harald@gigawatt.nl \
    --cc=dash@vger.kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=vda.linux@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.