Permalink
Browse files

Allow IniFile to work with files and strings that are otherwise prope…

…rly formatted but don't end with a newline
  • Loading branch information...
1 parent a924aca commit cdbdf2374d82c15b91466dde8685826035bc4e53 @erebor erebor committed Sep 14, 2012
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/inifile.rb
  2. +7 −0 test/test_inifile.rb
View
@@ -449,7 +449,7 @@ def parse!
# otherwise scan and store characters till we hit the start of some
# special section like a quote, newline, comment, etc.
else
- tmp = scanner.scan_until(%r/([\n"#{@param}#{@comment}]|\\[\[\]#{@param}#{@comment}"])/m)
+ tmp = scanner.scan_until(%r/([\n"#{@param}#{@comment}] | \z | \\[\[\]#{@param}#{@comment}"])/mx)
parse_error if tmp.nil?
len = scanner[1].length
View
@@ -252,6 +252,13 @@ def test_initialize
assert_raise(IniFile::Error) {IniFile.new :filename => 'test/data/bad_1.ini'}
end
+ def test_initialize_from_string_without_ending_newline
+ content = "[section_one]\n foo=bar"
+ ini_file = IniFile.new(content)
+ assert ini_file.has_section?('section_one')
+ assert_equal 'bar', ini_file['section_one']['foo']
+ end
+
def test_initialize_from_string
content = File.read('test/data/good.ini')

0 comments on commit cdbdf23

Please sign in to comment.