Skip to content

Commit 1714176

Browse files
author
matz
committed
* regex.c (re_compile_pattern): give warning for unescaped square
brackets and minus in character class. [ruby-dev:19868] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3593 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent dfb2c7a commit 1714176

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Fri Mar 21 23:23:45 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
2+
3+
* regex.c (re_compile_pattern): give warning for unescaped square
4+
brackets and minus in character class. [ruby-dev:19868]
5+
16
Fri Mar 21 18:12:20 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
27

38
* eval.c (bmcall): missing type.

eval.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7284,8 +7284,10 @@ static VALUE
72847284
bmcall(args, method)
72857285
VALUE args, method;
72867286
{
7287-
volatile VALUE args2 = svalue_to_avalue(args);
7288-
return method_call(RARRAY(args2)->len, RARRAY(args2)->ptr, method);
7287+
volatile VALUE a;
7288+
7289+
a = svalue_to_avalue(args);
7290+
return method_call(RARRAY(a)->len, RARRAY(a)->ptr, method);
72897291
}
72907292

72917293
static VALUE

regex.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ static int current_mbctype = MBCTYPE_ASCII;
185185

186186
#ifdef RUBY
187187
#include "util.h"
188+
# re_warning(x) rb_warn(x)
189+
#endif
190+
191+
#ifndef re_warning
192+
# define re_warning(x)
188193
#endif
189194

190195
static void
@@ -1464,6 +1469,7 @@ re_compile_pattern(pattern, size, bufp)
14641469
if (p == p0 + 1) {
14651470
if (p == pend)
14661471
FREE_AND_RETURN(stackb, "invalid regular expression; empty character class");
1472+
re_warning("character class has `]' without escape");
14671473
}
14681474
else
14691475
/* Stop if this isn't merely a ] inside a bracket
@@ -1481,6 +1487,9 @@ re_compile_pattern(pattern, size, bufp)
14811487
}
14821488
had_char_class = 0;
14831489

1490+
if (c == '-')
1491+
re_warning("character class has `-' without escape");
1492+
14841493
/* \ escapes characters when inside [...]. */
14851494
if (c == '\\') {
14861495
PATFETCH_RAW(c);
@@ -1678,13 +1687,16 @@ re_compile_pattern(pattern, size, bufp)
16781687
c1++;
16791688
while (c1--)
16801689
PATUNFETCH;
1690+
re_warning("character class has `[' without escape");
16811691
SET_LIST_BIT(TRANSLATE_P()?translate['[']:'[');
16821692
SET_LIST_BIT(TRANSLATE_P()?translate[':']:':');
16831693
had_char_class = 0;
16841694
last = ':';
16851695
}
16861696
}
16871697
else if (had_mbchar == 0 && (!current_mbctype || !had_num_literal)) {
1698+
if (c == '[')
1699+
re_warning("character class has `[' without escape");
16881700
SET_LIST_BIT(c);
16891701
had_num_literal = 0;
16901702
}

0 commit comments

Comments
 (0)