All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: grub-devel@gnu.org
Subject: Re: [PATCH] '.' causes wildcard expansion
Date: Mon, 18 Jun 2012 13:03:15 +0200	[thread overview]
Message-ID: <4FDF0AF3.3000503@gmail.com> (raw)
In-Reply-To: <4FD91756.9080200@comcast.net>


[-- Attachment #1.1: Type: text/plain, Size: 952 bytes --]

On 14.06.2012 00:42, Robert Mabee wrote:

> Having second thoughts.  Where I suggested taking out this call
> 
>> -      else if (isregexop (ch))
>> +      else if (ch == '*')    /* only wildcard currently implemented */
> I should have just taken the extraneous '.' out of isregexop.


It's used in other contexts as "needing escaping". So no, this part is fine

>  That would
> make it slightly simpler to add the remaining shell wildcards ('?' and '[')
> when desired.
> 
> '[' already works,

Not properly: try a[b*

> if there's also a * to trigger expansion, with the small
> bug that special chars within [] still get escaped or translated so the set
> may include an unexpected '.' or '\'.
> 
> Other regex chars also work, which probably should be counted as a
> bug.  I assume the eventual goal is to behave just like a common shell.

Please try attached patch
-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: regex.diff --]
[-- Type: text/x-diff; name="regex.diff", Size: 1267 bytes --]

=== modified file 'grub-core/commands/wildcard.c'
--- grub-core/commands/wildcard.c	2012-06-08 20:54:21 +0000
+++ grub-core/commands/wildcard.c	2012-06-18 11:01:31 +0000
@@ -80,7 +80,7 @@ merge (char **dest, char **ps)
 static inline int
 isregexop (char ch)
 {
-  return grub_strchr ("*.\\", ch) ? 1 : 0;
+  return grub_strchr ("*.\\|+{}[]", ch) ? 1 : 0;
 }
 
 static char *
@@ -128,14 +128,22 @@ make_regex (const char *start, const cha
 	{
 	case '\\':
 	  buffer[i++] = ch;
-	  if (*start != '\0')
+	  if (*start == '*' || *start == '?')
 	    buffer[i++] = *start++;
+	  else
+	    buffer[i++] = '\\';
 	  break;
 
 	case '.':
 	case '(':
 	case ')':
 	case '@':
+	case '|':
+	case '+':
+	case '{':
+	case '}':
+	case '[':
+	case ']':
 	  buffer[i++] = '\\';
 	  buffer[i++] = ch;
 	  break;
@@ -145,6 +153,10 @@ make_regex (const char *start, const cha
 	  buffer[i++] = '*';
 	  break;
 
+	case '?':
+	  buffer[i++] = '.';
+	  break;
+
 	default:
 	  buffer[i++] = ch;
 	}
@@ -181,7 +193,7 @@ split_path (const char *str, const char
       if (ch == '\\' && end[1])
 	end++;
 
-      else if (isregexop (ch))
+      else if (ch == '*' || ch == '?')
 	regex = 1;
 
       else if (ch == '/' && ! regex)


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

  reply	other threads:[~2012-06-18 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-11  6:56 [PATCH] '.' causes wildcard expansion Robert Mabee
2012-06-13 22:42 ` Robert Mabee
2012-06-18 11:03   ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2012-06-19 12:19   ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-06-20  8:04     ` Robert Mabee

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=4FDF0AF3.3000503@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /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.