All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dimitar Yurukov <mscalindt@gmail.com>
To: mscalindt@gmail.com
Cc: dash@vger.kernel.org, harald@gigawatt.nl
Subject: [PATCH v2] expand: Recognize '^' as a negation character in BE
Date: Fri, 16 Jul 2021 15:50:27 +0300	[thread overview]
Message-ID: <20210716125027.18824-1-mscalindt@gmail.com> (raw)
In-Reply-To: <20210716094227.15177-1-mscalindt@gmail.com>

While performing bracket expression ('[...]'), DASH recognizes only '!'
as a special character for negation/inversion, but POSIX specifies '^'.

The specification (2018 edition):
"
9.3.3 BRE Special Characters

^ The <circumflex> shall signify a non-matching list expression when it
  occurs first in a list, immediately following a <left-square-bracket>
  (see RE Bracket Expression).
"

DASH:
  $ i='123 asd' && printf "%s\n" "${i##*[!a-z]}"
  asd
  $ i='123 asd' && printf "%s\n" "${i##*[^a-z]}"

  $

BASH (with --posix):
  $ i='123 asd' && printf "%s\n" "${i##*[!a-z]}"
  asd
  $ i='123 asd' && printf "%s\n" "${i##*[^a-z]}"
  asd
  $

This patch makes <circumflex> ('^') a special character used to specify
negation/inversion.

Signed-off-by: Dimitar Yurukov <mscalindt@gmail.com>
---
Changes in v2:
  - Fixed the patch (patched expmeta())

 src/expand.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/expand.c b/src/expand.c
index 1730670..32a1b5a 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1296,7 +1296,7 @@ expmeta(char *name, unsigned name_len, unsigned expdir_len)
 			metaflag = 1;
 		else if (*p == '[') {
 			char *q = p + 1;
-			if (*q == '!')
+			if (*q == '!' || *q == '^')
 				q++;
 			for (;;) {
 				if (*q == '\\')
@@ -1565,7 +1565,7 @@ pmatch(const char *pattern, const char *string)
 
 			startp = p;
 			invert = 0;
-			if (*p == '!') {
+			if (*p == '!' || *p == '^') {
 				invert++;
 				p++;
 			}
-- 
2.32.0


  parent reply	other threads:[~2021-07-16 12:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-16  9:42 [PATCH] expand: Recognize '^' as a negation character in BE Dimitar Yurukov
2021-07-16 10:00 ` Harald van Dijk
2021-07-16 12:46   ` Dimitar Yurukov
2021-07-16 12:50 ` Dimitar Yurukov [this message]
2021-07-19  5:13   ` [PATCH v2] " Herbert Xu

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=20210716125027.18824-1-mscalindt@gmail.com \
    --to=mscalindt@gmail.com \
    --cc=dash@vger.kernel.org \
    --cc=harald@gigawatt.nl \
    /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.