特定のYAMLデータのloadでエラーになる場合がある

$B$O$8$a$^$7$F!"EZ5o$H?=$7$^$9!#(B
Ruby$B$G(BYAML$B$N=hM}$r$9$k:]$K!“IT6q9g$H;W$o$l$k5sF0$r8+$D$1$?$N$G$4Js9p$7$^$9!#(B
[email protected]$dFbMF$,E,@Z$G$J$1$l$P!”$4;XE&$/[email protected]$5$$!#(B

$B!Z35MW![(B
Ruby 1.9.3-p448$B$G(Bdump$B$7$?(BYAML$B%G!<%?$r(BRuby
2.0.0-p247$B$G(Bload$B$9$k$H(B
$B%(%i!<$K$J$k>l9g$,$"$k!#(B

$B!Z4D6-![(B
Ruby 1.9.3-p448 (RubyInstaller$BHG(B)
Ruby 2.0.0-p247 (RubyInstaller$BHG(B)
OS: WindowsXP Pro SP3

$B!Z<j=g![(B
(1) $B0J2<$N$h$&$K(Bdump.rb$B$H(Bload.rb$B$rMQ0U$9$k!#(B

[dump.rb]

-- coding: UTF-8 --

require ‘yaml’
File.open(“test.yml”, “w”) { |file|
YAML.dump("$B$M$3(B\n1", file)
}

[load.rb]

-- coding: UTF-8 --

require ‘yaml’
File.open(“test.yml”, “r”) { |file|
print YAML.load(file)
}

(2) Ruby 1.9.3-p448$B$G(Bdump.rb$B$r<B9T$9$k!#(Btest.yml$B$,$G$-$k!#(B

D:\Work\Ruby\bug_Psych>ruby -v
ruby 1.9.3p448 (2013-06-27) [i386-mingw32]

D:\Work\Ruby\bug_Psych>ruby dump.rb

[test.yml]
— ! '$B$M$3(B

1’

(3) Ruby 2.0.0-p247$B$G(Bload.rb$B$r<B9T$9$k$H!"%(%i!<$K$J$k!#(B

D:\Work\Ruby\bug_Psych>ruby -v
ruby 2.0.0p247 (2013-06-27) [i386-mingw32]

D:\Work\Ruby\bug_Psych>ruby load.rb
C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:114:in Integer': invalid value for Integer(): "\xE3\x81\xAD\xE3\x81\x93\n1" (ArgumentError) from C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:114:inparse_int’
from C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:102:in
tokenize' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:98:indeserialize’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:104:in
visit_Psych_Nodes_Scalar' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:invisit’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in
accept' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:inaccept’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:240:in
visit_Psych_Nodes_Document' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:invisit’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in
accept' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:inaccept’
from C:/Ruby200/lib/ruby/2.0.0/psych/nodes/node.rb:35:in
to_ruby' from C:/Ruby200/lib/ruby/2.0.0/psych.rb:130:inload’
from load.rb:5:in block in <main>' from load.rb:4:inopen’
from load.rb:4:in `’

(4)
dump.rb$BCf$N(BYAML.dump$B$KEO$9J8;zNs$K$h$C$F!"0J2<$N$h$&$K7k2L$,JQ$o$k!#(B

“$B$M$3(B\n1.0” $B"*(B $B%(%i!<(B
D:\Work\Ruby\bug_Psych>ruby load.rb
C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:99:in Float': invalid value for Float(): "\xE3\x81\xAD\xE3\x81\x93\n1.0" (ArgumentError) from C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:99:intokenize’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:98:in
deserialize' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:104:invisit_Psych_Nodes_Scalar’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:in
visit' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:inaccept’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:in
accept' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:240:invisit_Psych_Nodes_Document’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:in
visit' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:inaccept’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:in
accept' from C:/Ruby200/lib/ruby/2.0.0/psych/nodes/node.rb:35:into_ruby’
from C:/Ruby200/lib/ruby/2.0.0/psych.rb:130:in load' from load.rb:4:inblock in ’
from load.rb:3:in open' from load.rb:3:in

“$B$M$3(Ba\n1” $B"*(B $B%(%i!<(B
D:\Work\Ruby\bug_Psych>ruby load.rb
C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:114:in Integer': invalid value for Integer(): "\xE3\x81\xAD\xE3\x81\x93a\n1" (ArgumentError) from C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:114:inparse_int’
from C:/Ruby200/lib/ruby/2.0.0/psych/scalar_scanner.rb:102:in
tokenize' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:98:indeserialize’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:104:in
visit_Psych_Nodes_Scalar' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:invisit’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in
accept' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:inaccept’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:240:in
visit_Psych_Nodes_Document' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:15:invisit’
from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/visitor.rb:5:in
accept' from C:/Ruby200/lib/ruby/2.0.0/psych/visitors/to_ruby.rb:20:inaccept’
from C:/Ruby200/lib/ruby/2.0.0/psych/nodes/node.rb:35:in
to_ruby' from C:/Ruby200/lib/ruby/2.0.0/psych.rb:130:inload’
from load.rb:4:in block in <main>' from load.rb:3:inopen’
from load.rb:3:in `’

“a$B$M$3(B\n1” $B"*(B [email protected]>o=N;(B
“$B$M(B\n1” $B"
(B [email protected]>o=N;(B
“ab\n1” $B"
(B [email protected]>o=N;(B
“$B$M$3(B 1” $B"
(B [email protected]>o=N;(B
“$B$M$3(B\na1” $B"
(B [email protected]>o=N;(B
“$B$M$3(B\n1a” $B"
(B [email protected]>o=*N;(B

(5) $B85$N(Bdump.rb$B$r(BRuby
1.9.3-p448$B$G<B9T$7!"(Bload.rb$B$bF1$84D6-$G<B9T$7$?>l9g!"(B
[email protected]>o=*N;$9$k!#(B

(6) $B85$N(Bdump.rb$B$r(BRuby
2.0.0-p247$B$G<B9T$7$?>l9g$O(Btest.yml$B$,0J2<$N$h$&$K(B
$B$J$j!"$3$l$O(BRuby 1.9.3-p448$B$G$b(BRuby
[email protected]>o$K(Bload$B$G$-$k!#(B

[test.yml]
— |-
$B$M$3(B
1

(7) $B85$N(Bdump.rb$B$r(BRuby 1.9.3-p448$B$G<B9T$7!"$=$N4D6-$K(Bpsych
2.0.0$B$r%$%s%9%H!<%k(B
$B$7$?8e!"0J2<$N$h$&$K=q$-49$($?(Bload.rb$B$r<B9T$9$k$H%(%i!<$K$J$k!#(B

[load.rb]

-- coding: UTF-8 --

gem ‘psych’, ‘=2.0.0’ # $B"+DI2C(B
require ‘yaml’
File.open(“test.yml”, “r”) { |file|
print YAML.load(file)
}

D:\Work\Ruby\bug_Psych>ruby load.rb
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/scalar_scanner.rb:117:in
Integer': invalid value for Integer(): "\xE3\x81\xAD\xE3\x81\x93\n1" (ArgumentError) from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/scalar_scanner.rb:117:inparse_int’
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/scalar_scanner.rb:105:in
tokenize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/to_ruby.rb:114:indeserialize’
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/to_ruby.rb:120:in
visit_Psych_Nodes_Scalar' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/visitor.rb:15:invisit’
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/visitor.rb:5:in
accept' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/to_ruby.rb:31:inaccept’
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/to_ruby.rb:274:in
visit_Psych_Nodes_Document' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/visitor.rb:15:invisit’
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/visitor.rb:5:in
accept' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/visitors/to_ruby.rb:31:inaccept’
from
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych/nodes/node.rb:37:in
to_ruby' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-2.0.0/lib/psych.rb:245:inload’
from load.rb:5:in block in <main>' from load.rb:4:inopen’
from load.rb:4:in `’

(8)
psych$B$N:G?7HG(B(2.0.0)$B$N(B1$B$DA0$N%P!<%8%g%s(B(1.3.4)$B$G$I$&$J$k$+;n$=$&$H$7$?$,!"(B
Ruby 1.9.3-p448$B4D6-!"(BRuby
2.0.0-p247$B4D6-$H$b$K%$%s%9%H!<%k$K<:GT$7$?$?$a!"(B
$B;n$;$J$+$C$?!#(B

(Ruby 1.9.3-p448$B4D6-$G$N%(%i!<(B)
D:\Work\Ruby\bug_Psych>gem install psych -v “1.3.4”
Fetching: psych-1.3.4.gem (100%)
Temporarily enhancing PATH to include DevKit…
Building native extensions. This could take a while…
ERROR: Error installing psych:
ERROR: Failed to build gem native extension.

C:/Ruby193/bin/ruby.exe extconf.rb

checking for yaml.h… no
yaml.h is missing. Try ‘port install libyaml +universal’ or ‘yum install
libyaml-devel’
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=C:/Ruby193/bin/ruby
–with-libyaml-dir
–without-libyaml-dir
–with-libyaml-include
–without-libyaml-include=${libyaml-dir}/include
–with-libyaml-lib
–without-libyaml-lib=${libyaml-dir}/lib

Gem files will remain installed in
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-1.3.4 for inspection.
Results logged to
C:/Ruby193/lib/ruby/gems/1.9.1/gems/psych-1.3.4/ext/psych/gem_make.out

(Ruby 2.0.0-p247$B4D6-$G$N%(%i!<(B)
D:\Work\Ruby\bug_Psych>gem install psych -v “1.3.4”
Temporarily enhancing PATH to include DevKit…
Building native extensions. This could take a while…
ERROR: Error installing psych:
ERROR: Failed to build gem native extension.

C:/Ruby200/bin/ruby.exe extconf.rb

checking for yaml.h… no
yaml.h is missing. Try ‘port install libyaml +universal’ or ‘yum install
libyaml-devel’
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details.
You may
need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=C:/Ruby200/bin/ruby
–with-libyaml-dir
–without-libyaml-dir
–with-libyaml-include
–without-libyaml-include=${libyaml-dir}/include
–with-libyaml-lib
–without-libyaml-lib=${libyaml-dir}/

Gem files will remain installed in
C:/Ruby200/lib/ruby/gems/2.0.0/gems/psych-1.3.4 for inspection.
Results logged to
C:/Ruby200/lib/ruby/gems/2.0.0/gems/psych-1.3.4/ext/psych/gem_make.out

$B!ZHw9M![(B
Ruby 1.9.3-p448$B4D6-$G$b(Bpsych
2.0.0$B$r;H$&$h$&$K$7$F(BYAML.load$B$9$k$H%(%i!<$K(B
$B$J$k$?$a!"(Bpsych 2.0.0$B$KLdBj$,$"$k$N$G$O$J$$$+$H9M$($^$7$?!#(B
$B$7$+$7!"(BRuby
2.0.0-p247$B4D6-$G8E$$(Bpsych$B$r;H$C$?>l9g$I$&$J$k$+$r;n$;$J$+$C$?$N$G!"(B
Ruby$B<+BN$N%P!<%8%g%s$K0MB8$7$J$$$N$+$I$&$+$OJ,$+$j$^$;$s$G$7$?!#(B

$B0J>e$G$9!#(B