From bd4d26145e6dac851a5c275d1d9c45f99aaae649 Mon Sep 17 00:00:00 2001 From: Julien Reichardt Date: Sun, 8 Apr 2018 02:18:01 +0200 Subject: [PATCH] Keep empty sections when parsing INI --- spec/std/ini_spec.cr | 6 +++--- src/ini.cr | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/std/ini_spec.cr b/spec/std/ini_spec.cr index e0d3d517d16e..f61105e97426 100644 --- a/spec/std/ini_spec.cr +++ b/spec/std/ini_spec.cr @@ -35,7 +35,7 @@ describe "INI" do it "ignores 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..1f3a95a585f9 100644 --- a/src/ini.cr +++ b/src/ini.cr @@ -52,7 +52,7 @@ class INI end end - ini.delete_if { |_, v| v.empty? } + ini.delete("") if ini[""].empty? ini end