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

ruby-changes:59679

From: Nobuyoshi <ko1@a...>
Date: Sat, 11 Jan 2020 12:40:33 +0900 (JST)
Subject: [ruby-changes:59679] eb737916b1 (master): Warn when :newline precedes other newline options

https://git.ruby-lang.org/ruby.git/commit/?id=eb737916b1

From eb737916b1e435ff8212913c03e5798089b0d3fe Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 11 Jan 2020 10:19:29 +0900
Subject: Warn when :newline precedes other newline options


diff --git a/test/ruby/test_econv.rb b/test/ruby/test_econv.rb
index caa0fca..5a4af9b 100644
--- a/test/ruby/test_econv.rb
+++ b/test/ruby/test_econv.rb
@@ -922,7 +922,9 @@ class TestEncodingConverter < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_econv.rb#L922
     end
     newlines.each do |nl|
       opts = {newline: :universal, nl => true}
-      ec2 = Encoding::Converter.new("", "", **opts)
+      ec2 = assert_warning(/:newline option preceds/, opts.inspect) do
+        Encoding::Converter.new("", "", **opts)
+      end
       assert_equal(ec1, ec2)
     end
   end
diff --git a/transcode.c b/transcode.c
index a336f5d..5cdaaaf 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2418,6 +2418,7 @@ static int https://github.com/ruby/ruby/blob/trunk/transcode.c#L2418
 econv_opts(VALUE opt, int ecflags)
 {
     VALUE v;
+    int newlineflag = 0;
 
     v = rb_hash_aref(opt, sym_invalid);
     if (NIL_P(v)) {
@@ -2463,6 +2464,7 @@ econv_opts(VALUE opt, int ecflags) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2464
 #ifdef ENABLE_ECONV_NEWLINE_OPTION
     v = rb_hash_aref(opt, sym_newline);
     if (!NIL_P(v)) {
+        newlineflag = 2;
 	ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
 	if (v == sym_universal) {
 	    ecflags |= ECONV_UNIVERSAL_NEWLINE_DECORATOR;
@@ -2484,10 +2486,9 @@ econv_opts(VALUE opt, int ecflags) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2486
 	    rb_raise(rb_eArgError, "unexpected value for newline option");
 	}
     }
-    else
 #endif
     {
-	int setflags = 0, newlineflag = 0;
+        int setflags = 0;
 
 	v = rb_hash_aref(opt, sym_universal_newline);
 	if (RTEST(v))
@@ -2504,9 +2505,15 @@ econv_opts(VALUE opt, int ecflags) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2505
 	    setflags |= ECONV_CR_NEWLINE_DECORATOR;
 	newlineflag |= !NIL_P(v);
 
-	if (newlineflag) {
+        switch (newlineflag) {
+          case 1:
 	    ecflags &= ~ECONV_NEWLINE_DECORATOR_MASK;
 	    ecflags |= setflags;
+            break;
+
+          case 3:
+            rb_warning(":newline option preceds other newline options");
+            break;
 	}
     }
 
-- 
cgit v0.10.2


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

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