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

ruby-changes:36226

From: nobu <ko1@a...>
Date: Thu, 6 Nov 2014 23:58:50 +0900 (JST)
Subject: [ruby-changes:36226] nobu:r48307 (trunk): pack.c: escape and encoding

nobu	2014-11-06 23:58:43 +0900 (Thu, 06 Nov 2014)

  New Revision: 48307

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

  Log:
    pack.c: escape and encoding
    
    * pack.c (pack_pack): escape unprintable characters and preserve
      the encoding of warning message.

  Modified files:
    trunk/ChangeLog
    trunk/pack.c
    trunk/test/ruby/test_pack.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48306)
+++ ChangeLog	(revision 48307)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Nov  6 23:58:40 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* pack.c (pack_pack): escape unprintable characters and preserve
+	  the encoding of warning message.
+
 Thu Nov  6 23:55:18 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (sym_printable): QUOTE() should not raise an exception
Index: pack.c
===================================================================
--- pack.c	(revision 48306)
+++ pack.c	(revision 48307)
@@ -912,10 +912,19 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L912
 	    }
 	    break;
 
-	  default:
-	    rb_warning("unknown pack directive '%c' in '%s'",
-		type, RSTRING_PTR(fmt));
+	  default: {
+	    char unknown[5];
+	    if (ISPRINT(type)) {
+		unknown[0] = type;
+		unknown[1] = '\0';
+	    }
+	    else {
+		snprintf(unknown, sizeof(unknown), "\\x%.2x", type & 0xff);
+	    }
+	    rb_warning("unknown pack directive '%s' in '% "PRIsVALUE"'",
+		       unknown, fmt);
 	    break;
+	  }
 	}
     }
 
Index: test/ruby/test_pack.rb
===================================================================
--- test/ruby/test_pack.rb	(revision 48306)
+++ test/ruby/test_pack.rb	(revision 48307)
@@ -718,5 +718,13 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pack.rb#L718
     assert_warning(/unknown pack directive ',' in ','/) {
       [].pack(",")
     }
+    assert_warning(/\A[ -~]+\Z/) {
+      [].pack("\x7f")
+    }
+    assert_warning(/\A(.* in '\u{3042}'\n)+\z/) {
+      EnvUtil.with_default_external(Encoding::UTF_8) {
+        [].pack("\u{3042}")
+      }
+    }
   end
 end

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

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