Skip to content

Commit

Permalink
fixed: leading / in unquoted strings are not recognized
Browse files Browse the repository at this point in the history
  • Loading branch information
zookzook committed Mar 2, 2020
1 parent 6ef044b commit 84cbdc4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
7 changes: 2 additions & 5 deletions lib/hocon/tokenizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,8 @@ defmodule Hocon.Tokenizer do
def tokenize(<<"#", rest::bits>>, original, skip, tokens) do
skip_comment(rest, original, skip + 1, tokens)
end
def tokenize(<<"/", rest::bits>>, original, skip, tokens) do
case rest do
<<"/", rest::bits>> -> skip_comment(rest, original, skip + 2, tokens)
_ -> tokenize(rest, original, skip + 1, tokens) ## todo error
end
def tokenize(<<"//", rest::bits>> = string, original, skip, tokens) do
skip_comment(rest, original, skip + 2, tokens)
end
def tokenize(<<"+=", rest::bits>>, original, skip, tokens) do
tokenize(rest, original, skip + 2, Tokens.push(tokens, :concat_array))
Expand Down
3 changes: 3 additions & 0 deletions test/hocon_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ defmodule HoconTest do
assert {:ok, %{"a" => [%{"list" => [%{"kind" => "Dog", "name" => "Greta"}, %{"kind" => "Dog", "name" => "Tom"}]}]}} == Hocon.decode(~s(a : [ { list : [{ name : Greta, kind : Dog }, { name : Tom, kind : Dog }]}]))
end

test "heading /" do
assert {:ok, %{"a" => "/2019/gfx/image.png"}} == Hocon.decode(~s(a : /2019/gfx/image.png))
end
end
2 changes: 1 addition & 1 deletion test/parser/substitutions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Parser.SubstitutionsTest do
assert {:ok, %{"path" => "/home/greta"}} == Hocon.decode(~s(path : ${MY_HOME}))
System.put_env("MY_HOME", "/home")
assert {:ok, %{"path" => "/home/greta"}} == Hocon.decode(~s(path : ${MY_HOME}\n path : ${path}"/greta"))
assert {:ok, %{"path" => ["/home", "usr/bin"]}} == Hocon.decode(~s(path : [${MY_HOME}]\n path : ${path} [ /usr/bin ]))
assert {:ok, %{"path" => ["/home", "/usr/bin"]}} == Hocon.decode(~s(path : [${MY_HOME}]\n path : ${path} [ /usr/bin ]))
end

test "Parsing += field separator" do
Expand Down
4 changes: 2 additions & 2 deletions test/tokenizer/tokenizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ defmodule TokenizerTest do

test "unquoted strings" do
assert {:ok, [{:unquoted_string, "this"}, :open_square, :close_square, {:unquoted_string, "string"}]} == Tokenizer.decode(~s(this [] string))
assert {:ok, [{:unquoted_string, "path/to/file"}]} == Tokenizer.decode(~s(/path/to/file))
assert {:ok, [{:unquoted_string, "path/to"}]} == Tokenizer.decode(~s(/path/to// now we have a comment))
assert {:ok, [{:unquoted_string, "/path/to/file"}]} == Tokenizer.decode(~s(/path/to/file))
assert {:ok, [{:unquoted_string, "/path/to"}]} == Tokenizer.decode(~s(/path/to// now we have a comment))
end

test "Tokenize numbers" do
Expand Down

0 comments on commit 84cbdc4

Please sign in to comment.