Skip to content

Commit

Permalink
* regex.c (re_compile_pattern): give warning for unescaped square
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
matz committed Mar 21, 2003
1 parent dfb2c7a commit 1714176
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Fri Mar 21 23:23:45 2003 Yukihiro Matsumoto <[email protected]>

* regex.c (re_compile_pattern): give warning for unescaped square
brackets and minus in character class. [ruby-dev:19868]

Fri Mar 21 18:12:20 2003 Nobuyoshi Nakada <[email protected]>

* eval.c (bmcall): missing type.
Expand Down
6 changes: 4 additions & 2 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7284,8 +7284,10 @@ static VALUE
bmcall(args, method)
VALUE args, method;
{
volatile VALUE args2 = svalue_to_avalue(args);
return method_call(RARRAY(args2)->len, RARRAY(args2)->ptr, method);
volatile VALUE a;

a = svalue_to_avalue(args);
return method_call(RARRAY(a)->len, RARRAY(a)->ptr, method);
}

static VALUE
Expand Down
12 changes: 12 additions & 0 deletions regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ static int current_mbctype = MBCTYPE_ASCII;

#ifdef RUBY
#include "util.h"
# re_warning(x) rb_warn(x)
#endif

#ifndef re_warning
# define re_warning(x)
#endif

static void
Expand Down Expand Up @@ -1464,6 +1469,7 @@ re_compile_pattern(pattern, size, bufp)
if (p == p0 + 1) {
if (p == pend)
FREE_AND_RETURN(stackb, "invalid regular expression; empty character class");
re_warning("character class has `]' without escape");
}
else
/* Stop if this isn't merely a ] inside a bracket
Expand All @@ -1481,6 +1487,9 @@ re_compile_pattern(pattern, size, bufp)
}
had_char_class = 0;

if (c == '-')
re_warning("character class has `-' without escape");

/* \ escapes characters when inside [...]. */
if (c == '\\') {
PATFETCH_RAW(c);
Expand Down Expand Up @@ -1678,13 +1687,16 @@ re_compile_pattern(pattern, size, bufp)
c1++;
while (c1--)
PATUNFETCH;
re_warning("character class has `[' without escape");
SET_LIST_BIT(TRANSLATE_P()?translate['[']:'[');
SET_LIST_BIT(TRANSLATE_P()?translate[':']:':');
had_char_class = 0;
last = ':';
}
}
else if (had_mbchar == 0 && (!current_mbctype || !had_num_literal)) {
if (c == '[')
re_warning("character class has `[' without escape");
SET_LIST_BIT(c);
had_num_literal = 0;
}
Expand Down

0 comments on commit 1714176

Please sign in to comment.