1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* dir.c (has_magic, find_dirsep): incomplete '[' matches no character

in Dir.glob. (follows File.fnmatch's behavior)

* dir.c (fnmatch_helper): incomplete escape is ignored in File.fnmatch.
  (follows Dir.glob's behavior)

* dir.c (find_dirsep): '/' between '[' and ']' is ignored in Dir.glob.
  (follows File.fnmatch with File::FNM_PATHNAME 's behavior)

* dir.c (find_dirsep): escaped slash '\/' loses its meaning as
  directory separator in Dir.glob.

[ruby-dev:23291]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ocean 2004-04-09 08:06:01 +00:00
parent d9420d0568
commit ae9512fcf6
2 changed files with 66 additions and 21 deletions

View file

@ -1,3 +1,19 @@
Fri Apr 9 17:05:21 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* dir.c (has_magic, find_dirsep): incomplete '[' matches no character
in Dir.glob. (follows File.fnmatch's behavior)
* dir.c (fnmatch_helper): incomplete escape is ignored in File.fnmatch.
(follows Dir.glob's behavior)
* dir.c (find_dirsep): '/' between '[' and ']' is ignored in Dir.glob.
(follows File.fnmatch with File::FNM_PATHNAME 's behavior)
* dir.c (find_dirsep): escaped slash '\/' loses its meaning as
directory separator in Dir.glob.
[ruby-dev:23291]
Thu Apr 8 20:25:19 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/extmk.rb (extmake): skip uncompiled extensions.

71
dir.c
View file

@ -210,7 +210,7 @@ bracket(p, s, flags)
End marker itself won't be compared.
And if function succeeds, *pcur reaches end marker.
*/
#define UNESCAPE(p) (escape && *(p) == '\\' && (p)[1] ? (p) + 1 : (p))
#define UNESCAPE(p) (escape && *(p) == '\\' ? (p) + 1 : (p))
#define ISEND(p) (!*(p) || (pathname && *(p) == '/'))
#define RETURN(val) return *pcur = p, *scur = s, (val);
@ -940,28 +940,21 @@ do_opendir(path)
/* Return nonzero if S has any special globbing chars in it. */
static int
has_magic(s, flags)
const char *s;
int flags;
const char *s;
int flags;
{
const int escape = !(flags & FNM_NOESCAPE);
register const char *p = s;
register char c;
int open = 0;
int escape = !(flags & FNM_NOESCAPE);
while (c = *p++) {
switch (c) {
case '?':
case '*':
case '?':
case '[':
return 1;
case '[': /* Only accept an open brace if there is a close */
open++; /* brace to match it. Bracket expressions must be */
continue; /* complete, according to Posix.2 */
case ']':
if (open)
return 1;
continue;
case '\\':
if (escape && !(c = *p++))
return 0;
@ -974,6 +967,44 @@ has_magic(s, flags)
return 0;
}
/* Find separator in globbing pattern. */
static char *
find_dirsep(s, flags)
const char *s;
int flags;
{
const int escape = !(flags & FNM_NOESCAPE);
register const char *p = s;
register char c;
int open = 0;
while (c = *p++) {
switch (c) {
case '[':
open = 1;
continue;
case ']':
open = 0;
continue;
case '/':
if (!open)
return (char *)p-1;
continue;
case '\\':
if (escape && !(c = *p++))
return (char *)p-1;
continue;
}
p = Next(p-1);
}
return (char *)p-1;
}
/* Remove escaping baskclashes */
static void
remove_backslashes(p)
@ -1013,23 +1044,21 @@ glob_make_pattern(p, flags)
const char *p;
int flags;
{
char *buf;
int dirsep = 0; /* pattern terminates with '/' */
struct glob_pattern *list, *tmp, **tail = &list;
int dirsep = 0; /* pattern is terminated with '/' */
while (*p) {
tmp = ALLOC(struct glob_pattern);
if (p[0] == '*' && p[1] == '*' && p[2] == '/') {
/* fold continuous RECURSIVEs */
/* fold continuous RECURSIVEs (needed in glob_helper) */
do { p += 3; } while (p[0] == '*' && p[1] == '*' && p[2] == '/');
tmp->type = RECURSIVE;
tmp->str = 0;
dirsep = 1;
}
else {
const char *m;
for (m = p; *m && *m != '/'; Inc(m));
buf = ALLOC_N(char, m-p+1);
const char *m = find_dirsep(p, flags);
char *buf = ALLOC_N(char, m-p+1);
memcpy(buf, p, m-p);
buf[m-p] = '\0';
tmp->type = has_magic(buf, flags) ? MAGICAL : PLAIN;
@ -1267,7 +1296,7 @@ glob_helper(path, dirsep, exist, isdir, beg, end, flags, func, arg)
for (cur = copy_beg; cur < copy_end; ++cur) {
if (*cur) {
char *buf, *name;
char *name, *buf;
name = ALLOC_N(char, strlen((*cur)->str) + 1);
strcpy(name, (*cur)->str);
if (escape) remove_backslashes(name);