TwP / inifile

Native Ruby package for reading and writing INI files
http://codeforpeople.rubyforge.org/inifile
95 stars 47 forks source link

Error: file starts with a comment #55

Closed C-Ezra-M closed 1 year ago

C-Ezra-M commented 1 year ago

I tried to load a file that starts with the below, but it threw an IniFile::Error for some reason.

# See the documentation on the wiki to learn how to edit this file.
#-------------------------------
[BULBASAUR]
Name = Bulbasaur
Types = GRASS,POISON
BaseStats = 45,49,49,45,65,65
GenderRatio = FemaleOneEighth
GrowthRate = Parabolic
BaseExp = 64

The error is:

C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:578:in `error': Could not parse line: "# See the documentation on the wiki to learn how to edit this file." (IniFile::Error)
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:532:in `block in parse'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:515:in `each_line'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:515:in `parse'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:400:in `parse'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:128:in `block in read'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:128:in `open'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:128:in `read'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:80:in `initialize'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:31:in `new'
        from C:/tools/ruby31/lib/ruby/gems/3.1.0/gems/inifile-3.0.0/lib/inifile.rb:31:in `load'
        from spreadsheet_prepare.rb:5:in `<main>'

I'm trying to make a script, and it starts with the following:

require 'inifile'

pokemon = ARGV[0]
phash = IniFile.load("PBS/pokemon.txt")
phash.merge(IniFile.load("PBS/pokemon-forms.txt"))
mhash = IniFile.load("PBS/moves.txt")
C-Ezra-M commented 1 year ago

I just found out, the file is UTF-8 encoded with BOM, so this is probably what caused the error.

C-Ezra-M commented 1 year ago

The BOM was indeed the problem. Changing the file's character encoding helped.