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

* re.c (rb_reg_prepare_enc): error condition was updated for non

ASCII compatible strings.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2008-05-15 10:45:58 +00:00
parent a8a1114efe
commit 880a96c795
2 changed files with 34 additions and 20 deletions

View file

@ -7,6 +7,11 @@ Thu May 15 15:33:59 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (rb_file_s_extname): ditto.
Thu May 15 13:23:20 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (rb_reg_prepare_enc): error condition was updated for non
ASCII compatible strings.
Thu May 15 12:19:42 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/openssl/openssl_missing.c (HMAC_CTX_copy): adopted to

49
re.c
View file

@ -1146,6 +1146,15 @@ rb_reg_preprocess(const char *p, const char *end, rb_encoding *enc,
rb_encoding **fixed_enc, onig_errmsg_buffer err);
static void
reg_enc_error(VALUE re, VALUE str)
{
rb_raise(rb_eArgError,
"incompatible encoding regexp match (%s regexp with %s string)",
rb_enc_name(RREGEXP(re)->ptr->enc),
rb_enc_name(rb_enc_get(str)));
}
static rb_encoding*
rb_reg_prepare_enc(VALUE re, VALUE str, int warn)
{
@ -1158,27 +1167,27 @@ rb_reg_prepare_enc(VALUE re, VALUE str, int warn)
}
rb_reg_check(re);
/* ignorecase status */
if (rb_reg_fixed_encoding_p(re) || !rb_enc_str_asciicompat_p(str)) {
if (ENCODING_GET(re) != rb_enc_get_index(str) &&
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
rb_raise(rb_eArgError,
"incompatible encoding regexp match (%s regexp with %s string)",
rb_enc_name(rb_enc_from_index(ENCODING_GET(re))),
rb_enc_name(rb_enc_get(str)));
}
}
else {
enc = rb_enc_get(str);
if (warn && (RBASIC(re)->flags & REG_ENCODING_NONE) &&
enc != rb_ascii8bit_encoding() &&
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
rb_warn("regexp match /.../n against to %s string",
rb_enc_name(enc));
enc = rb_enc_get(str);
if (!rb_enc_str_asciicompat_p(str)) {
if (RREGEXP(re)->ptr->enc != enc) {
reg_enc_error(re, str);
}
return enc;
}
return RREGEXP(re)->ptr->enc;
else if (rb_reg_fixed_encoding_p(re)) {
if (RREGEXP(re)->ptr->enc != enc &&
(!rb_enc_asciicompat(RREGEXP(re)->ptr->enc) ||
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT)) {
reg_enc_error(re, str);
}
enc = RREGEXP(re)->ptr->enc;
}
if (warn && (RBASIC(re)->flags & REG_ENCODING_NONE) &&
enc != rb_ascii8bit_encoding() &&
rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
rb_warn("regexp match /.../n against to %s string",
rb_enc_name(enc));
}
return enc;
}
regex_t *
@ -2282,7 +2291,7 @@ rb_reg_initialize(VALUE obj, const char *s, int len, rb_encoding *enc,
}
re->ptr = make_regexp(RSTRING_PTR(unescaped), RSTRING_LEN(unescaped), enc,
options & ARG_REG_OPTION_MASK, err);
options & ARG_REG_OPTION_MASK, err);
if (!re->ptr) return -1;
re->str = ALLOC_N(char, len+1);
memcpy(re->str, s, len);