Skip to content

Commit

Permalink
bugfix: . in quoted strings are not interpreted any more
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Jan 10, 2020
1 parent 7122141 commit 48d71d7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.6
* Bugfix
* . in quoted strings are not interpreted any more

## 0.1.5
* Enhancements
* added support for url resolvers
Expand Down
4 changes: 4 additions & 0 deletions lib/hocon/document.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ defmodule Hocon.Document do
def put(doc, key, %Document{root: value}, tokens, opts) do
put(doc, key, value, tokens, opts)
end
def put(%Document{root: root}, {:string, key}, value, tokens, opts) do
{rest, root} = put_path(root, [key], value, [], tokens, opts)
{rest, %Document{root: root}}
end
def put(%Document{root: root}, key, value, tokens, opts) do
path = key
|> String.split(".")
Expand Down
4 changes: 2 additions & 2 deletions lib/hocon/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ defmodule Hocon.Parser do
end
defp parse_object([{:string, key}, :open_curly | rest], result, root, opts) do
{rest, value} = parse_object(rest, Document.new(), false, opts)
{rest, doc} = Document.put(result, key, value, rest, opts)
{rest, doc} = Document.put(result, {:string, key}, value, rest, opts)
parse_object(rest, doc, root, opts)
end
defp parse_object([{:string, key}, :colon | rest], result, root, opts) do
{rest, value} = parse(rest, opts)
{rest, doc} = Document.put(result, key, value, rest, opts)
{rest, doc} = Document.put(result, {:string, key}, value, rest, opts)
parse_object(rest, doc, root, opts)
end
defp parse_object([{:unquoted_string, key}, :open_curly | rest], result, root, opts) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Hocon.MixProject do
use Mix.Project

@version "0.1.5"
@version "0.1.6"

def project do
[
Expand Down
10 changes: 10 additions & 0 deletions test/parser/quoted_strings_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Parser.QuotedStringTest do
use ExUnit.Case, async: true

test "Parsing quoted strings as keys" do
assert {:ok, %{"a.b.c" => 1}} == Hocon.decode(~s("a.b.c" : 1))
assert {:ok, %{"a" => %{"a.b.c" => 1}}} == Hocon.decode(~s( a : { "a.b.c" : 1 }))
assert {:ok, %{"a" => %{"b" => %{"c" => %{"a.b.c" => 1}}}}} == Hocon.decode(~s( a.b.c : { "a.b.c" : 1 }))
end

end

0 comments on commit 48d71d7

Please sign in to comment.