Bug #6849
closedPsych.load_file throws TypeError for empty file
Description
When parsing an empty file via Psych.load_file:
TypeError: no implicit conversion from nil to integer
I would expect that an empty hash or array would be returned.
This, more directly, relates to parsing YAML documents using YAML.load_file
Files
Updated by zzak (zzak _) over 11 years ago
On ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
I can reproduce this using Psych.load_file.
However, when I try Psych#load as the implementation suggests[1]
leaving out the utf stuff "bom|utf-8"; it returns false:
$irb
require 'psych'
touch empty.yml
File.open('empty.yml', 'r') { |f| Psych.load(f,'empty file') }
#=> false
Something is up with the File.open mode used by psych:
$irb
touch empty.file
File.open('empty.file', 'r:bom|utf-8') { |f| puts f }
TypeError: no implicit conversion from nil to integer
1: https://github.com/tenderlove/psych/blob/master/lib/psych.rb#L299
On Thu, Aug 9, 2012 at 2:54 PM, BrandonMathis (Brandon Mathis)
BeMathis@gmail.com wrote:
Issue #6849 has been reported by BrandonMathis (Brandon Mathis).
Bug #6849: Psych.load_file throws TypeError for empty file
https://bugs.ruby-lang.org/issues/6849Author: BrandonMathis (Brandon Mathis)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]When parsing an empty file via Psych.load_file:
TypeError: no implicit conversion from nil to integer
I would expect that an empty hash or array would be returned.This, more directly, relates to parsing YAML documents using YAML.load_file
Updated by Anonymous over 11 years ago
On Tue, Aug 14, 2012 at 03:12:58AM +0900, Zachary Scott wrote:
On ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
I can reproduce this using Psych.load_file.
However, when I try Psych#load as the implementation suggests[1]
leaving out the utf stuff "bom|utf-8"; it returns false:$irb
require 'psych'
touch empty.yml
File.open('empty.yml', 'r') { |f| Psych.load(f,'empty file') }
#=> falseSomething is up with the File.open mode used by psych:
$irb
touch empty.file
File.open('empty.file', 'r:bom|utf-8') { |f| puts f }
TypeError: no implicit conversion from nil to integer
Ah, this is a bug in Ruby:
https://bugs.ruby-lang.org/issues/6487
It should be fixed in the next 1.9.3 patch release.
--
Aaron Patterson
http://tenderlovemaking.com/
Updated by zzak (zzak _) over 11 years ago
- Status changed from Open to Closed
This is a duplicate of #6487