From 23fc875fd81aa0f0dcc9082b957e0bd18c2e9907 Mon Sep 17 00:00:00 2001 From: Julien Reichardt Date: Sat, 7 Apr 2018 22:05:48 +0200 Subject: [PATCH] Keep empty sections when parsing INI --- spec/std/ini_spec.cr | 8 ++++---- src/ini.cr | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/std/ini_spec.cr b/spec/std/ini_spec.cr index e0d3d517d16e..9ff946f9abcc 100644 --- a/spec/std/ini_spec.cr +++ b/spec/std/ini_spec.cr @@ -33,9 +33,9 @@ describe "INI" do INI.parse("key = ").should eq({"" => {"key" => ""}}) end - it "ignores whitespaces" do + it "parses whitespaces" do INI.parse(" key = value ").should eq({"" => {"key" => "value"}}) - INI.parse(" [foo]").should eq({} of String => Hash(String, String)) + INI.parse(" [foo]").should eq({"foo" => Hash(String, String).new}) end it "ignores comments" do @@ -50,8 +50,8 @@ describe "INI" do INI.parse("[foo]\na=1\n[foo]\nb=2").should eq({"foo" => {"a" => "1", "b" => "2"}}) end - it "ignores an empty section" do - INI.parse("[section]").should eq({} of String => Hash(String, String)) + it "parses empty section" do + INI.parse("[section]").should eq({"section" => Hash(String, String).new}) end it "parses a file" do diff --git a/src/ini.cr b/src/ini.cr index f47c5744f01e..0b2f4050d6f1 100644 --- a/src/ini.cr +++ b/src/ini.cr @@ -52,7 +52,7 @@ class INI end end - ini.delete_if { |_, v| v.empty? } + return ini.reject("") if ini[""].empty? ini end