Skip to content

Commit

Permalink
Merge pull request #148 from dreid/empty-keys
Browse files Browse the repository at this point in the history
Support empty keys by quoting them. Fixes #147
  • Loading branch information
emancu authored Jan 31, 2024
2 parents 12b0048 + 6572c45 commit a9553af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/toml-rb/dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def to_toml(obj)
end

def bare_key?(key)
!!key.to_s.match(/^[a-zA-Z0-9_-]*$/)
!!key.to_s.match(/^[a-zA-Z0-9_-]+$/)
end

# The key needs to use quotes according to TOML specs.
Expand Down
7 changes: 7 additions & 0 deletions test/dumper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,11 @@ def test_dump_special_chars_in_strings

assert_equal %("\\t" = "escape special chars in strings") + "\n", dumped
end

def test_dump_empty_key
hash = {"" => "empty key"}
dumped = TomlRB.dump(hash)

assert_equal %("" = "empty key") + "\n", dumped
end
end

0 comments on commit a9553af

Please sign in to comment.