Permalink
Browse files

when trying to convert a string into a numeric type, raise an excepti…

…on in case the string encoding isn't ASCII incompatible

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4421 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 28e0309 commit 51c47d94f988264e2a27248e375d6bb05880853c @lrz lrz committed Aug 11, 2010
Showing with 10 additions and 0 deletions.
  1. +2 −0 bignum.c
  2. +8 −0 encoding.h
View
@@ -12,6 +12,7 @@
#include "ruby/macruby.h"
#include "objc.h"
+#include "encoding.h"
#include <math.h>
#include <float.h>
@@ -593,6 +594,7 @@ rb_str_to_inum(VALUE str, int base, int badcheck)
long len;
StringValue(str);
+ str_check_ascii_compatible(str);
if (badcheck) {
s = StringValueCStr(str);
}
View
@@ -359,6 +359,14 @@ rb_str_t *str_need_string(VALUE str);
rb_str_t *replacement_string_for_encoding(rb_encoding_t* enc);
void str_replace_with_string(rb_str_t *self, rb_str_t *source);
+static inline void
+str_check_ascii_compatible(VALUE str)
+{
+ if (IS_RSTR(str) && !RSTR(str)->encoding->ascii_compatible) {
+ rb_raise(rb_eEncCompatError, "ASCII incompatible encoding: %s",
+ RSTR(str)->encoding->public_name);
+ }
+}
#if defined(__cplusplus)
} // extern "C"

0 comments on commit 51c47d9

Please sign in to comment.