[前][次][番号順一覧][スレッド一覧]

ruby-changes:13742

From: yugui <ko1@a...>
Date: Wed, 28 Oct 2009 23:15:27 +0900 (JST)
Subject: [ruby-changes:13742] Ruby:r25535 (ruby_1_9_1): merges r24569 from trunk into ruby_1_9_1.

yugui	2009-10-28 23:15:07 +0900 (Wed, 28 Oct 2009)

  New Revision: 25535

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25535

  Log:
    merges r24569 from trunk into ruby_1_9_1.
    --
    * parse.y (lex_get_str, lex_io_gets, rb_parser_compile_string):
      must be ascii compatible.

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/parse.y
    branches/ruby_1_9_1/test/ruby/test_eval.rb
    branches/ruby_1_9_1/version.h

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 25534)
+++ ruby_1_9_1/ChangeLog	(revision 25535)
@@ -1,3 +1,8 @@
+Mon Aug 17 14:35:03 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (lex_get_str, lex_io_gets, rb_parser_compile_string):
+	  must be ascii compatible.
+
 Sun Aug 16 23:58:22 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (yylex): should dispatch scan-event even when follows
Index: ruby_1_9_1/parse.y
===================================================================
--- ruby_1_9_1/parse.y	(revision 25534)
+++ ruby_1_9_1/parse.y	(revision 25535)
@@ -5076,10 +5076,21 @@
 }
 #endif /* !RIPPER */
 
+static rb_encoding *
+must_be_ascii_compatible(VALUE s)
+{
+    rb_encoding *enc = rb_enc_get(s);
+    if (!rb_enc_asciicompat(enc)) {
+	rb_raise(rb_eArgError, "invalid source encoding");
+    }
+    return enc;
+}
+
 static VALUE
 lex_get_str(struct parser_params *parser, VALUE s)
 {
     char *beg, *end, *pend;
+    rb_encoding *enc = must_be_ascii_compatible(s);
 
     beg = RSTRING_PTR(s);
     if (lex_gets_ptr) {
@@ -5092,18 +5103,20 @@
 	if (*end++ == '\n') break;
     }
     lex_gets_ptr = end - RSTRING_PTR(s);
-    return rb_enc_str_new(beg, end - beg, rb_enc_get(s));
+    return rb_enc_str_new(beg, end - beg, enc);
 }
 
 static VALUE
 lex_getline(struct parser_params *parser)
 {
     VALUE line = (*parser->parser_lex_gets)(parser, parser->parser_lex_input);
+    if (NIL_P(line)) return line;
+    must_be_ascii_compatible(line);
 #ifndef RIPPER
-    if (ruby_debug_lines && !NIL_P(line)) {
+    if (ruby_debug_lines) {
 	rb_ary_push(ruby_debug_lines, line);
     }
-    if (ruby_coverage && !NIL_P(line)) {
+    if (ruby_coverage) {
 	rb_ary_push(ruby_coverage, Qnil);
     }
 #endif
@@ -5111,17 +5124,9 @@
 }
 
 #ifndef RIPPER
-NODE*
-rb_compile_string(const char *f, VALUE s, int line)
+static NODE*
+parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
 {
-    VALUE volatile vparser = rb_parser_new();
-
-    return rb_parser_compile_string(vparser, f, s, line);
-}
-
-NODE*
-rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
-{
     struct parser_params *parser;
     NODE *node;
     volatile VALUE tmp;
@@ -5140,15 +5145,31 @@
 }
 
 NODE*
+rb_compile_string(const char *f, VALUE s, int line)
+{
+    must_be_ascii_compatible(s);
+    return parser_compile_string(rb_parser_new(), f, s, line);
+}
+
+NODE*
+rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
+{
+    must_be_ascii_compatible(s);
+    return parser_compile_string(vparser, f, s, line);
+}
+
+NODE*
 rb_compile_cstr(const char *f, const char *s, int len, int line)
 {
-    return rb_compile_string(f, rb_str_new(s, len), line);
+    VALUE str = rb_str_new(s, len);
+    return parser_compile_string(rb_parser_new(), f, str, line);
 }
 
 NODE*
 rb_parser_compile_cstr(volatile VALUE vparser, const char *f, const char *s, int len, int line)
 {
-    return rb_parser_compile_string(vparser, f, rb_str_new(s, len), line);
+    VALUE str = rb_str_new(s, len);
+    return parser_compile_string(vparser, f, str, line);
 }
 
 static VALUE
Index: ruby_1_9_1/version.h
===================================================================
--- ruby_1_9_1/version.h	(revision 25534)
+++ ruby_1_9_1/version.h	(revision 25535)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.1"
-#define RUBY_PATCHLEVEL 294
+#define RUBY_PATCHLEVEL 295
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_1/test/ruby/test_eval.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_eval.rb	(revision 25534)
+++ ruby_1_9_1/test/ruby/test_eval.rb	(revision 25535)
@@ -408,4 +408,11 @@
       assert_equal("0", f.read.chomp)
     end
   end
+
+  def test_eval_ascii_incompatible
+    assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-16be"))}
+    assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-16le"))}
+    assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-32be"))}
+    assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-32le"))}
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]