summaryrefslogtreecommitdiff
path: root/regex.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-21 14:37:32 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-21 14:37:32 +0000
commit1714176963ccec3a6aa7498c6d2b4ba7139eea3a (patch)
treec280fedf9b1a4919be5c82f3b312b91bd9561b3c /regex.c
parentdfb2c7aa14f8453832e8c8c75e394d1bca6bd570 (diff)
* 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
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/regex.c b/regex.c
index 9ea73da..7ae16cf 100644
--- a/regex.c
+++ b/regex.c
@@ -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
@@ -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
@@ -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);
@@ -1678,6 +1687,7 @@ 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;
@@ -1685,6 +1695,8 @@ re_compile_pattern(pattern, size, bufp)
}
}
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;
}