summaryrefslogtreecommitdiff
path: root/regparse.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-10 07:00:44 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-10 07:00:44 +0000
commit83b76913d86935640344664e682656bf8f379119 (patch)
treedf1357f5cc054c67af4cc6b252e1137edf1e3bd8 /regparse.c
parentee647e1b96982c7ff459d7af1a6109f7d54f61c1 (diff)
downloadruby-83b76913d86935640344664e682656bf8f379119.tar.gz
Warn unknown escaped chars in regexp.
* regparse.c (UNKNOWN_ESC_WARN): added. * regparse.c (conv_backslash_value): Warn unknown escaped chars in regexp. [ruby-dev:39104] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'regparse.c')
-rw-r--r--regparse.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/regparse.c b/regparse.c
index 9295e1d5ab..b9667c6f67 100644
--- a/regparse.c
+++ b/regparse.c
@@ -2115,6 +2115,8 @@ or_cclass(CClassNode* dest, CClassNode* cc, ScanEnv* env)
return 0;
}
+static void UNKNOWN_ESC_WARN(ScanEnv *env, int c);
+
static int
conv_backslash_value(int c, ScanEnv* env)
{
@@ -2133,6 +2135,8 @@ conv_backslash_value(int c, ScanEnv* env)
break;
default:
+ if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
+ UNKNOWN_ESC_WARN(env, c);
break;
}
}
@@ -2885,6 +2889,22 @@ CC_DUP_WARN(ScanEnv *env)
}
}
+static void
+UNKNOWN_ESC_WARN(ScanEnv *env, int c)
+{
+ UChar buf[WARN_BUFSIZE];
+ if (onig_warn == onig_null_warn || !RTEST(ruby_verbose)) return ;
+
+ onig_snprintf_with_pattern(buf, WARN_BUFSIZE, env->enc,
+ env->pattern, env->pattern_end,
+ (UChar* )"Unknown escape \\%c is ignored", c);
+
+ if (env->sourcefile == NULL)
+ (*onig_warn)((char* )buf);
+ else
+ rb_compile_warn(env->sourcefile, env->sourceline, (char* )buf);
+}
+
static UChar*
find_str_position(OnigCodePoint s[], int n, UChar* from, UChar* to,
UChar **next, OnigEncoding enc)