summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-29 09:37:00 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-29 09:37:00 +0000
commit93e925ffd4fbc84a62d4fea51a9828d0be3fbf43 (patch)
treef8be6277c27122da8a73dd96f19003f32fd83d05
parentb253f3561794b8bbcedeeee3eec37565172e2cc4 (diff)
downloadruby-93e925ffd4fbc84a62d4fea51a9828d0be3fbf43.tar.gz
ruby-93e925ffd4fbc84a62d4fea51a9828d0be3fbf43.tar.xz
ruby-93e925ffd4fbc84a62d4fea51a9828d0be3fbf43.zip
* encoding.c (enc_compatible_p): raise TypeError when argument is not
String nor Regexp. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--encoding.c10
2 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index ca67590b3..6a84f5fe8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Aug 29 18:22:27 2008 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * encoding.c (enc_compatible_p): raise TypeError when argument is not
+ String nor Regexp.
+
Fri Aug 29 18:20:56 2008 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_str_index_m): only regexp uses byte offset.
diff --git a/encoding.c b/encoding.c
index 291070dd1..21614245a 100644
--- a/encoding.c
+++ b/encoding.c
@@ -880,8 +880,14 @@ enc_compatible_p(VALUE klass, VALUE str1, VALUE str2)
{
rb_encoding *enc;
- if (enc_check_encoding(str1) > 0 || enc_check_encoding(str2) > 0)
- rb_raise(rb_eTypeError, "wrong argument type Encoding (expected String)");
+ if (BUILTIN_TYPE(str1) != T_STRING && BUILTIN_TYPE(str1) != T_REGEXP) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Regexp)",
+ rb_obj_classname(str1));
+ }
+ if (BUILTIN_TYPE(str2) != T_STRING && BUILTIN_TYPE(str2) != T_REGEXP) {
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected String or Regexp)",
+ rb_obj_classname(str2));
+ }
if (!enc_capable(str1)) return Qnil;
if (!enc_capable(str2)) return Qnil;
enc = rb_enc_compatible(str1, str2);