[#36071] サマータイムでのsleepの動作について — Yoshikawa <yoshixool@...>

吉川と申します。

16 messages 2008/09/01
[#36074] Re: サマータイムでのsleepの動作について — "U.Nakamura" <usa@...> 2008/09/01

こんにちは、なかむら(う)です。

[#36084] Re: サマータイムでのsleepの動作について — Yoshikawa <yoshixool@...> 2008/09/01

吉川です。

[#36090] Re: サマータイムでのsleepの動作について — "U.Nakamura" <usa@...> 2008/09/02

こんにちは、なかむら(う)です。

[#36132] [Feature #542] cgi.rb : CGI::unescape return encoding — Takeyuki Fujioka <redmine@...>

Feature #542: cgi.rb : CGI::unescape return encoding

48 messages 2008/09/03
[#36145] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — "NARUSE, Yui" <naruse@...> 2008/09/03

成瀬です。

[#36146] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/04

藤岡です。

[#36161] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/05

藤岡です。

[#36239] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Tanaka Akira <akr@...> 2008/09/10

In article <48C0C20E.4000307@rabbix.jp>,

[#36242] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Tietew <tietew@...> 2008/09/10

[#36244] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/10

藤岡です。

[#36261] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Tanaka Akira <akr@...> 2008/09/10

In article <48C76705.5000202@rabbix.jp>,

[#36263] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/11

藤岡です。

[#36282] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Tanaka Akira <akr@...> 2008/09/12

In article <48C8A83E.8000200@rabbix.jp>,

[#36289] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/13

藤岡です。

[#36332] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — "NARUSE, Yui" <naruse@...> 2008/09/16

成瀬です。

[#36341] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Tietew <tietew@...> 2008/09/17

[#36342] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/17

藤岡です。

[#36345] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Tietew <tietew@...> 2008/09/17

[#36384] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/19

藤岡です。

[#36422] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/21

藤岡です。

[#36425] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Kazuhiro NISHIYAMA <zn@...> 2008/09/21

西山和広です。

[#36427] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/21

藤岡です。

[#36428] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — "NARUSE, Yui" <naruse@...> 2008/09/21

成瀬です。

[#36430] Re: [Feature #542] cgi.rb : CGI::unescape return encoding — Fujioka <fuj@...> 2008/09/21

藤岡です。

[#36147] GNU iconv dependency — Takahiro Kambe <taca@...>

こんにちは。

28 messages 2008/09/04
[#36222] Re: GNU iconv dependency — "NARUSE, Yui" <naruse@...> 2008/09/08

成瀬です。

[#36248] Re: GNU iconv dependency — Takahiro Kambe <taca@...> 2008/09/10

In message <48C544C3.6090607@airemix.jp>

[#36249] Re: GNU iconv dependency — "NARUSE, Yui" <naruse@...> 2008/09/10

成瀬です。

[#36250] Re: GNU iconv dependency — Takahiro Kambe <taca@...> 2008/09/10

In message <48C7D1E1.5040403@airemix.jp>

[#36256] Re: GNU iconv dependency — "NARUSE, Yui" <naruse@...> 2008/09/10

Takahiro Kambe wrote:

[#36257] Re: GNU iconv dependency — Takahiro Kambe <taca@...> 2008/09/10

In message <48C7EC6B.5060306@airemix.jp>

[#36258] Re: GNU iconv dependency — "NARUSE, Yui" <naruse@...> 2008/09/10

Takahiro Kambe wrote:

[#36259] Re: GNU iconv dependency — Takahiro Kambe <taca@...> 2008/09/10

In message <48C7F8DD.7060001@airemix.jp>

[#36281] 合成文字の2コードポイント目 — "NARUSE, Yui" <naruse@...>

成瀬です。

24 messages 2008/09/12
[#36283] Re: 合成文字の2コードポイント目 — Yukihiro Matsumoto <matz@...> 2008/09/13

まつもと ゆきひろです

[#36286] Re: 合成文字の2コードポイント目 — Tanaka Akira <akr@...> 2008/09/13

In article <E1KeKG9-0004NC-Jb@x61.netlab.jp>,

[#36287] Re: 合成文字の2コードポイント目 — Yukihiro Matsumoto <matz@...> 2008/09/13

まつもと ゆきひろです

[#36292] Re: 合成文字の2コードポイント目 — Tanaka Akira <akr@...> 2008/09/14

In article <E1KeRWe-00037N-Vb@x61.netlab.jp>,

[#36293] Re: 合成文字の2コードポイント目 — "NARUSE, Yui" <naruse@...> 2008/09/14

成瀬です。

[#36304] Re: 合成文字の2コードポイント目 — Tanaka Akira <akr@...> 2008/09/15

In article <48CC86FD.3000409@airemix.jp>,

[#36306] Re: 合成文字の2コードポイント目 — "NARUSE, Yui" <naruse@...> 2008/09/15

Tanaka Akira wrote:

[#36310] Re: 合成文字の2コードポイント目 — Tanaka Akira <akr@...> 2008/09/15

In article <48CE068E.3080701@airemix.jp>,

[#36314] Re: 合成文字の2コードポイント目 — "NARUSE, Yui" <naruse@...> 2008/09/15

成瀬です。

[#36315] Re: 合成文字の2コードポイント目 — Yukihiro Matsumoto <matz@...> 2008/09/15

まつもと ゆきひろです

[#36316] Re: 合成文字の2コードポイント目 — Tanaka Akira <akr@...> 2008/09/16

In article <E1KfNyE-0005XO-0P@x61.netlab.jp>,

[#36317] Re: 合成文字の2コードポイント目 — Yukihiro Matsumoto <matz@...> 2008/09/16

まつもと ゆきひろです

[#36290] adding Pathname#abspath() — "Akinori MUSHA" <knu@...>

 SUSv3のrealpath(3)の項には、存在しないコンポーネントがあったら

18 messages 2008/09/13
[#36291] adding Pathname#resolve (was: adding Pathname#abspath()) — "Akinori MUSHA" <knu@...> 2008/09/13

 名前が良くなかったですね。Pathname#resolve()でどうでしょうか。

[#36297] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — Tanaka Akira <akr@...> 2008/09/14

In article <86wshfn0zl.knu@iDaemons.org>,

[#36308] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — "Akinori MUSHA" <knu@...> 2008/09/15

At Sun, 14 Sep 2008 23:20:56 +0900,

[#36437] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — Tanaka Akira <akr@...> 2008/09/22

In article <86vdwxn9rh.knu@iDaemons.org>,

[#36456] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — "Akinori MUSHA" <knu@...> 2008/09/22

At Mon, 22 Sep 2008 12:43:18 +0900,

[#36489] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — Tanaka Akira <akr@...> 2008/09/23

In article <86od2gcvvj.knu@iDaemons.org>,

[#36560] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — "Akinori MUSHA" <knu@...> 2008/09/25

At Wed, 24 Sep 2008 02:02:59 +0900,

[#36582] Re: adding Pathname#resolve (was: adding Pathname#abspath()) — Tanaka Akira <akr@...> 2008/09/25

In article <86ljxgd0jt.knu@iDaemons.org>,

[#36325] mathn (#**) — Tadayoshi Funaba <tadf@...>

mahtn した場合、

16 messages 2008/09/16

[#36346] add "Error" suffix for Encoding Exceptions — Tadashi Saito <shiba@...2.accsnet.ne.jp>

斎藤と申します。

18 messages 2008/09/17
[#36356] Re: add "Error" suffix for Encoding Exceptions — "NARUSE, Yui" <naruse@...> 2008/09/17

成瀬です。

[#36366] Re: add "Error" suffix for Encoding Exceptions — Tadashi Saito <shiba@...2.accsnet.ne.jp> 2008/09/18

斎藤と申します。

[#36371] Re: add "Error" suffix for Encoding Exceptions — "Yusuke ENDOH" <mame@...> 2008/09/18

遠藤です。

[#36349] Complex/image — Tadayoshi Funaba <tadf@...>

[ruby-math:00543] を読んで、image はやめて imag に変更したらどうか、つ

16 messages 2008/09/17
[#36363] Re: Complex/image — keiju@... (石塚圭樹) 2008/09/18

けいじゅ@いしつかです.

[#36372] Re: Complex/image — Tadayoshi Funaba <tadf@...> 2008/09/18

> imageとimagの件ですが, 現行では両方定義されているけど, imageは削除って

[#36448] [Feature #583] TmpdirとTempfile — Yuki Sonoda <redmine@...>

Feature #583: TmpdirとTempfile

11 messages 2008/09/22

[#36461] {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...>

Complex と Rational では、Unify が定義された場合、可能なら整数等に正規

36 messages 2008/09/22
[#36468] Re: {Complex,Rational}::Unify — Yukihiro Matsumoto <matz@...> 2008/09/22

まつもと ゆきひろです

[#36472] Re: {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...> 2008/09/22

> mathn.rbはcomplex.rbなどと同一の作者が同時に(一体として)作成

[#36483] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/09/23

けいじゅ@いしつかです.

[#36487] Re: {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...> 2008/09/23

> まず, Unifyなしで動作するように, mathn側で対応させてください. それから,

[#36520] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/09/24

けいじゅ@いしつかです.

[#36561] Re: {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...> 2008/09/25

> mathn動かなくなっていると思うので, あまり大丈夫ではありません.

[#36566] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/09/25

けいじゅ@いしつかです.

[#36605] Re: {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...> 2008/09/26

> これらのメソッドを呼び出すのではなく, 再定義することによって振る舞いを

[#36608] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/09/26

けいじゅ@いしつかです.

[#36609] Re: {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...> 2008/09/26

> 当然, mathnで対応することはできます.

[#36651] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/10/01

けいじゅ@いしつかです.

[#36654] Re: {Complex,Rational}::Unify — Tadayoshi Funaba <tadf@...> 2008/10/02

> >それで、僕が改めて言うまでもないことですが、mathn は石塚さんの担当なの

[#36657] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/10/03

けいじゅ@いしつかです.

[#36658] Re: {Complex,Rational}::Unify — Yukihiro Matsumoto <matz@...> 2008/10/03

まつもと ゆきひろです

[#36883] Re: {Complex,Rational}::Unify — keiju@... (石塚圭樹) 2008/10/23

けいじゅ@いしつかです.

[#36903] Re: {Complex,Rational}::Unify — Yukihiro Matsumoto <matz@...> 2008/10/24

まつもと ゆきひろです

[#36512] Encoding.default_internal のためのパッチ — Martin Duerst <duerst@...>

[ruby-core:18774] に Michael Selig から Encoding::default_internal

57 messages 2008/09/24
[#36517] Re: Encoding.default_internal のためのパッチ — "NARUSE, Yui" <naruse@...> 2008/09/24

成瀬です。

[#36523] Re: Encoding.default_internal のためのパッチ — Yukihiro Matsumoto <matz@...> 2008/09/24

まつもと ゆきひろです

[#36550] Re: Encoding.default_internal のためのパッチ — Nobuyoshi Nakada <nobu@...> 2008/09/25

なかだです。

[#36551] Re: Encoding.default_internal のためのパッチ — Yukihiro Matsumoto <matz@...> 2008/09/25

まつもと ゆきひろです

[#36554] Re: Encoding.default_internal のためのパッチ — Martin Duerst <duerst@...> 2008/09/25

At 14:58 08/09/25, Yukihiro Matsumoto wrote:

[#36556] Re: Encoding.default_internal のためのパッチ — Yukihiro Matsumoto <matz@...> 2008/09/25

まつもと ゆきひろです

[#36547] [Feature #600] cgi.rbのマルチパートフォームの受信は1.8との互換性が低い — Takeyuki Fujioka <redmine@...>

Feature #600: cgi.rbのマルチパートフォームの受信は1.8との互換性が低い

7 messages 2008/09/25

[#36628] [IA-64]BigDecimal#sqrt の仕様 — TAKANO Mitsuhiro <takano32@...>

こんにちは

15 messages 2008/09/30
[#36630] Re: [IA-64]BigDecimal#sqrt の仕様 — TAKANO Mitsuhiro <takano32@...> 2008/09/30

高野です。

[ruby-dev:36519] Re: [Feature #471] pack format 'm' based on RFC 4648

From: "Yusuke ENDOH" <mame@...>
Date: 2008-09-24 13:54:30 UTC
List: ruby-dev #36519
遠藤です。

2008/09/24 7:13 Tanaka Akira <akr@fsij.org>:
> In article <e0b1e5700809231144n376fd4eencfe06c49ed66665e@mail.gmail.com>,
>  "Yusuke ENDOH" <mame@tsg.ne.jp> writes:
>
>> うーん。base64.rb には decode_b とか b64encode とか禍々しい
>> メソッドがあるので、個人的にはあまり復活させたくないところ
>> です。
>
> そのへんは消しちゃっていいと思います。


そのへんと deprecated なコードを消しちゃったらだいぶすっきりしました。

module Base64 は以下の 6 つの module_function を持ちます。

- Base64.encode64         : RFC 2045 準拠なエンコード (改行を入れる)
- Base64.decode64         : RFC 2045 準拠なデコード (改行などを無視する)
- Base64.strict_encode64  : RFC 4648 準拠なエンコード (改行を入れない)
- Base64.strict_decode64  : RFC 4648 準拠なデコード (改行や = の不足は例外)
- Base64.urlsafe_encode64 : URL セーフなバリアントのエンコード
- Base64.urlsafe_decode64 : URL セーフなバリアントのデコード

standard_encode64 は RFC を意識しすぎな名前だなぁと思ったので、
一般ユーザにわかりやすそうな strict にしてみました。
standard の方が良ければ直します。

これでよければコミットしたいと思いますが、いかがでしょうか。


Index: pack.c
===================================================================
--- pack.c	(revision 19526)
+++ pack.c	(working copy)
@@ -362,7 +362,7 @@
 #endif
 static const char toofew[] = "too few arguments";

-static void encodes(VALUE,const char*,long,int);
+static void encodes(VALUE,const char*,long,int,int);
 static void qpencode(VALUE,VALUE,long);

 static unsigned long utf8_to_uv(const char*,long*);
@@ -887,6 +887,11 @@
 	    ptr = RSTRING_PTR(from);
 	    plen = RSTRING_LEN(from);

+	    if (len == 0) {
+		encodes(res, ptr, plen, type, 0);
+		ptr += plen;
+		break;
+	    }
 	    if (len <= 2)
 		len = 45;
 	    else
@@ -898,7 +903,7 @@
 		    todo = len;
 		else
 		    todo = plen;
-		encodes(res, ptr, todo, type);
+		encodes(res, ptr, todo, type, 1);
 		plen -= todo;
 		ptr += todo;
 	    }
@@ -1007,7 +1012,7 @@
 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

 static void
-encodes(VALUE str, const char *s, long len, int type)
+encodes(VALUE str, const char *s, long len, int type, int tail_lf)
 {
     char buff[4096];
     long i = 0;
@@ -1048,7 +1053,7 @@
 	buff[i++] = padding;
 	buff[i++] = padding;
     }
-    buff[i++] = '\n';
+    if (tail_lf) buff[i++] = '\n';
     rb_str_buf_cat(str, buff, i);
 }

@@ -1793,7 +1798,7 @@
 	    {
 		VALUE buf = infected_str_new(0, (send - s)*3/4, str);
 		char *ptr = RSTRING_PTR(buf);
-		int a = -1,b = -1,c = 0,d;
+		int a = -1,b = -1,c = 0,d = 0;
 		static signed char b64_xtable[256];

 		if (b64_xtable['/'] <= 0) {
@@ -1806,32 +1811,64 @@
 			b64_xtable[(unsigned char)b64_table[i]] = i;
 		    }
 		}
-		while (s < send) {
-		    a = b = c = d = -1;
-		    while ((a = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
-		    if (s >= send) break;
-		    s++;
-		    while ((b = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
-		    if (s >= send) break;
-		    s++;
-		    while ((c = b64_xtable[(unsigned char)*s]) == -1 && s < send)
{if (*s == '=') break; s++;}
-		    if (*s == '=' || s >= send) break;
-		    s++;
-		    while ((d = b64_xtable[(unsigned char)*s]) == -1 && s < send)
{if (*s == '=') break; s++;}
-		    if (*s == '=' || s >= send) break;
-		    s++;
-		    *ptr++ = a << 2 | b >> 4;
-		    *ptr++ = b << 4 | c >> 2;
-		    *ptr++ = c << 6 | d;
-		}
-		if (a != -1 && b != -1) {
-		    if (c == -1 && *s == '=')
+		if (len == 0) {
+		    while (s < send) {
+			a = b = c = d = -1;
+			a = b64_xtable[(unsigned char)*s++];
+			if (s >= send || a == -1) rb_raise(rb_eArgError, "invalid base64");
+			b = b64_xtable[(unsigned char)*s++];
+			if (s >= send || b == -1) rb_raise(rb_eArgError, "invalid base64");
+			if (*s == '=') {
+			    if (s + 2 == send && *(s + 1) == '=') break;
+			    rb_raise(rb_eArgError, "invalid base64");
+			}
+			c = b64_xtable[(unsigned char)*s++];
+			if (s >= send || c == -1) rb_raise(rb_eArgError, "invalid base64");
+			if (s + 1 == send && *s == '=') break;
+			d = b64_xtable[(unsigned char)*s++];
+			if (d == -1) rb_raise(rb_eArgError, "invalid base64");
 			*ptr++ = a << 2 | b >> 4;
-		    else if (c != -1 && *s == '=') {
+			*ptr++ = b << 4 | c >> 2;
+			*ptr++ = c << 6 | d;
+		    }
+		    if (c == -1) {
 			*ptr++ = a << 2 | b >> 4;
+			if (b & 0xf) rb_raise(rb_eArgError, "invalid base64");
+		    }
+		    else if (d == -1) {
+			*ptr++ = a << 2 | b >> 4;
 			*ptr++ = b << 4 | c >> 2;
+			if (c & 0x3) rb_raise(rb_eArgError, "invalid base64");
 		    }
 		}
+		else {
+		    while (s < send) {
+			a = b = c = d = -1;
+			while ((a = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
+			if (s >= send) break;
+			s++;
+			while ((b = b64_xtable[(unsigned char)*s]) == -1 && s < send) {s++;}
+			if (s >= send) break;
+			s++;
+			while ((c = b64_xtable[(unsigned char)*s]) == -1 && s < send) {if
(*s == '=') break; s++;}
+			if (*s == '=' || s >= send) break;
+			s++;
+			while ((d = b64_xtable[(unsigned char)*s]) == -1 && s < send) {if
(*s == '=') break; s++;}
+			if (*s == '=' || s >= send) break;
+			s++;
+			*ptr++ = a << 2 | b >> 4;
+			*ptr++ = b << 4 | c >> 2;
+			*ptr++ = c << 6 | d;
+		    }
+		    if (a != -1 && b != -1) {
+			if (c == -1 && *s == '=')
+			    *ptr++ = a << 2 | b >> 4;
+			else if (c != -1 && *s == '=') {
+			    *ptr++ = a << 2 | b >> 4;
+			    *ptr++ = b << 4 | c >> 2;
+			}
+		    }
+		}
 		rb_str_set_len(buf, ptr - RSTRING_PTR(buf));
 		UNPACK_PUSH(buf);
 	    }
Index: lib/base64.rb
===================================================================
--- lib/base64.rb	(revision 0)
+++ lib/base64.rb	(revision 0)
@@ -0,0 +1,91 @@
+#
+# = base64.rb: methods for base64-encoding and -decoding stings
+#
+
+# The Base64 module provides for the encoding (#encode64, #strict_encode64,
+# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
+# #urlsafe_decode64) of binary data using a Base64 representation.
+#
+# == Example
+#
+# A simple encoding and decoding.
+#
+#     require "base64"
+#
+#     enc   = Base64.encode64('Send reinforcements')
+#                         # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
+#     plain = Base64.decode64(enc)
+#                         # -> "Send reinforcements"
+#
+# The purpose of using base64 to encode data is that it translates any
+# binary data into purely printable characters.
+
+module Base64
+  module_function
+
+  # Returns the Base64-encoded version of +bin+.
+  # This method complies with RFC 2045.
+  # Line feeds are added to every 60 encoded charactors.
+  #
+  #    require 'base64'
+  #    Base64.encode64("Now is the time for all good coders\nto learn Ruby")
+  #
+  # <i>Generates:</i>
+  #
+  #    Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
+  #    UnVieQ==
+  def encode64(bin)
+    [bin].pack("m")
+  end
+
+  # Returns the Base64-decoded version of +str+.
+  # This method complies with RFC 2045.
+  # Characters outside the base alphabet are ignored.
+  #
+  #   require 'base64'
+  #   str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
+  #         'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
+  #         'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
+  #   puts Base64.decode64(str)
+  #
+  # <i>Generates:</i>
+  #
+  #    This is line one
+  #    This is line two
+  #    This is line three
+  #    And so on...
+  def decode64(str)
+    str.unpack("m").first
+  end
+
+  # Returns the Base64-encoded version of +bin+.
+  # This method complies with RFC 4648.
+  # No line feeds are added.
+  def strict_encode64(bin)
+    [bin].pack("m0")
+  end
+
+  # Returns the Base64-decoded version of +str+.
+  # This method complies with RFC 4648.
+  # ArgumentError is raised if +str+ is incorrectly padded or contains
+  # non-alphabet characters.  Note that CR or LF are also rejected.
+  def strict_decode64(str)
+    str.unpack("m0").first
+  end
+
+  # Returns the Base64-encoded version of +bin+.
+  # This method complies with ``Base 64 Encoding with URL and Filename Safe
+  # Alphabet'' in RFC 4648.
+  # The alphabet uses '-' instead of '+' and '_' instead of '/'.
+  def urlsafe_encode64(bin)
+    strict_encode64(bin).tr("+/", "-_")
+  end
+
+  # Returns the Base64-decoded version of +str+.
+  # This method complies with ``Base 64 Encoding with URL and Filename Safe
+  # Alphabet'' in RFC 4648.
+  # The alphabet uses '-' instead of '+' and '_' instead of '/'.
+  def urlsafe_decode64(str)
+    strict_decode64(str.tr("-_", "+/"))
+  end
+end
Index: test/ruby/test_pack.rb
===================================================================
--- test/ruby/test_pack.rb	(revision 19526)
+++ test/ruby/test_pack.rb	(working copy)
@@ -379,6 +379,36 @@
     assert_equal(["\377\377\377"], "////\n".unpack("m"))
   end

+  def test_pack_unpack_m0
+    assert_equal("", [""].pack("m0"))
+    assert_equal("AA==", ["\0"].pack("m0"))
+    assert_equal("AAA=", ["\0\0"].pack("m0"))
+    assert_equal("AAAA", ["\0\0\0"].pack("m0"))
+    assert_equal("/w==", ["\377"].pack("m0"))
+    assert_equal("//8=", ["\377\377"].pack("m0"))
+    assert_equal("////", ["\377\377\377"].pack("m0"))
+
+    assert_equal([""], "".unpack("m0"))
+    assert_equal(["\0"], "AA==".unpack("m0"))
+    assert_equal(["\0\0"], "AAA=".unpack("m0"))
+    assert_equal(["\0\0\0"], "AAAA".unpack("m0"))
+    assert_equal(["\377"], "/w==".unpack("m0"))
+    assert_equal(["\377\377"], "//8=".unpack("m0"))
+    assert_equal(["\377\377\377"], "////".unpack("m0"))
+
+    assert_raise(ArgumentError) { "^".unpack("m0") }
+    assert_raise(ArgumentError) { "A".unpack("m0") }
+    assert_raise(ArgumentError) { "A^".unpack("m0") }
+    assert_raise(ArgumentError) { "AA".unpack("m0") }
+    assert_raise(ArgumentError) { "AA=".unpack("m0") }
+    assert_raise(ArgumentError) { "AA===".unpack("m0") }
+    assert_raise(ArgumentError) { "AA=x".unpack("m0") }
+    assert_raise(ArgumentError) { "AAA".unpack("m0") }
+    assert_raise(ArgumentError) { "AAA^".unpack("m0") }
+    assert_raise(ArgumentError) { "AB==".unpack("m0") }
+    assert_raise(ArgumentError) { "AAB=".unpack("m0") }
+  end
+
   def test_pack_unpack_M
     assert_equal("a b c\td =\n\ne=\n", ["a b c\td \ne"].pack("M"))
     assert_equal(["a b c\td \ne"], "a b c\td =\n\ne=\n".unpack("M"))
Index: test/base64/test_base64.rb
===================================================================
--- test/base64/test_base64.rb	(revision 0)
+++ test/base64/test_base64.rb	(revision 0)
@@ -0,0 +1,99 @@
+require "test/unit"
+require "base64"
+
+class TestBase64 < Test::Unit::TestCase
+  def test_sample
+    assert_equal("U2VuZCByZWluZm9yY2VtZW50cw==\n",
Base64.encode64('Send reinforcements'))
+    assert_equal('Send reinforcements',
Base64.decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n"))
+    assert_equal(
+      "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n",
+      Base64.encode64("Now is the time for all good coders\nto learn Ruby"))
+    assert_equal(
+      "Now is the time for all good coders\nto learn Ruby",
+      Base64.decode64("Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nUnVieQ==\n"))
+    assert_equal(
+      "VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGlu\nZSB0aHJlZQpBbmQgc28gb24uLi4K\n",
+      Base64.encode64("This is line one\nThis is line two\nThis is
line three\nAnd so on...\n"))
+    assert_equal(
+      "This is line one\nThis is line two\nThis is line three\nAnd so on...\n",
+      Base64.decode64("VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGluZSB0aHJlZQpBbmQgc28gb24uLi4K"))
+  end
+
+  def test_encode64
+    assert_equal("", Base64.encode64(""))
+    assert_equal("AA==\n", Base64.encode64("\0"))
+    assert_equal("AAA=\n", Base64.encode64("\0\0"))
+    assert_equal("AAAA\n", Base64.encode64("\0\0\0"))
+    assert_equal("/w==\n", Base64.encode64("\377"))
+    assert_equal("//8=\n", Base64.encode64("\377\377"))
+    assert_equal("////\n", Base64.encode64("\377\377\377"))
+    assert_equal("/+8=\n", Base64.encode64("\xff\xef"))
+  end
+
+  def test_decode64
+    assert_equal("", Base64.decode64(""))
+    assert_equal("\0", Base64.decode64("AA==\n"))
+    assert_equal("\0\0", Base64.decode64("AAA=\n"))
+    assert_equal("\0\0\0", Base64.decode64("AAAA\n"))
+    assert_equal("\377", Base64.decode64("/w==\n"))
+    assert_equal("\377\377", Base64.decode64("//8=\n"))
+    assert_equal("\377\377\377", Base64.decode64("////\n"))
+    assert_equal("\xff\xef", Base64.decode64("/+8=\n"))
+  end
+
+  def test_strict_encode64
+    assert_equal("", Base64.strict_encode64(""))
+    assert_equal("AA==", Base64.strict_encode64("\0"))
+    assert_equal("AAA=", Base64.strict_encode64("\0\0"))
+    assert_equal("AAAA", Base64.strict_encode64("\0\0\0"))
+    assert_equal("/w==", Base64.strict_encode64("\377"))
+    assert_equal("//8=", Base64.strict_encode64("\377\377"))
+    assert_equal("////", Base64.strict_encode64("\377\377\377"))
+    assert_equal("/+8=", Base64.strict_encode64("\xff\xef"))
+  end
+
+  def test_strict_decode64
+    assert_equal("", Base64.strict_decode64(""))
+    assert_equal("\0", Base64.strict_decode64("AA=="))
+    assert_equal("\0\0", Base64.strict_decode64("AAA="))
+    assert_equal("\0\0\0", Base64.strict_decode64("AAAA"))
+    assert_equal("\377", Base64.strict_decode64("/w=="))
+    assert_equal("\377\377", Base64.strict_decode64("//8="))
+    assert_equal("\377\377\377", Base64.strict_decode64("////"))
+    assert_equal("\xff\xef", Base64.strict_decode64("/+8="))
+
+    assert_raise(ArgumentError) { Base64.strict_decode64("^") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("A") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("A^") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AA") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AA=") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AA===") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AA=x") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AAA") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AAA^") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AB==") }
+    assert_raise(ArgumentError) { Base64.strict_decode64("AAB=") }
+  end
+
+  def test_urlsafe_encode64
+    assert_equal("", Base64.urlsafe_encode64(""))
+    assert_equal("AA==", Base64.urlsafe_encode64("\0"))
+    assert_equal("AAA=", Base64.urlsafe_encode64("\0\0"))
+    assert_equal("AAAA", Base64.urlsafe_encode64("\0\0\0"))
+    assert_equal("_w==", Base64.urlsafe_encode64("\377"))
+    assert_equal("__8=", Base64.urlsafe_encode64("\377\377"))
+    assert_equal("____", Base64.urlsafe_encode64("\377\377\377"))
+    assert_equal("_-8=", Base64.urlsafe_encode64("\xff\xef"))
+  end
+
+  def test_urlsafe_decode64
+    assert_equal("", Base64.urlsafe_decode64(""))
+    assert_equal("\0", Base64.urlsafe_decode64("AA=="))
+    assert_equal("\0\0", Base64.urlsafe_decode64("AAA="))
+    assert_equal("\0\0\0", Base64.urlsafe_decode64("AAAA"))
+    assert_equal("\377", Base64.urlsafe_decode64("_w=="))
+    assert_equal("\377\377", Base64.urlsafe_decode64("__8="))
+    assert_equal("\377\377\377", Base64.urlsafe_decode64("____"))
+    assert_equal("\xff\xef", Base64.urlsafe_decode64("_+8="))
+  end
+end

-- 
Yusuke ENDOH <mame@tsg.ne.jp>

In This Thread