Skip to content

Commit

Permalink
Support empty keys by quoting them. Fixes #147
Browse files Browse the repository at this point in the history
  • Loading branch information
dreid committed Jan 31, 2024
1 parent 12b0048 commit 6572c45
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
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
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 6572c45

Please sign in to comment.