Skip to content

Commit

Permalink
Merge pull request #7 from brigadier/master
Browse files Browse the repository at this point in the history
allow unicode (utf8) and everything in values
  • Loading branch information
waisbrot authored Oct 10, 2016
2 parents c0e4fa5 + aa578ae commit 4f5517d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/eini_lexer.xrl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ Definitions.
%% Characters for keys
K = [a-zA-Z0-9_\-\.]+

%% Characters for values, printable except =, [ and ]

%% \x3b : $;
%% \x3d : $=
%% \x5b : $[
%% \x5d : $]
V = [\x21-\x3a\x3c\x3e-\x5a\x5c\x5e-\x7e]+
V = [^\x3b\x3d\x5b\x5d\x0d\x0a\s\t]+


%% spaces and breaks
S = [\s\t]
Expand Down
34 changes: 27 additions & 7 deletions test/eini_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ one_section_title_and_one_prop_test_() ->
)),
%% Multi blank lines after a prop
?_assertEqual({ok, [
{title,
{title,
[{key1, <<"value1">>}]}
]},
parse(
Expand Down Expand Up @@ -407,17 +407,17 @@ lex_error_title_test_() ->
fun teardown/ 1,
[
%% vertical tab in section title
?_assertMatch({error, {illegal_character, 1, _Reason}},
?_assertMatch({error, {syntax_error, 1, _Reason}},
parse("[ti\vtle]")),
?_assertMatch({error, {illegal_character, 3, _Reason}},
?_assertMatch({error, {syntax_error, 3, _Reason}},
parse(
"[titleA]\n"
"keyA1=valueA1\n"
"[tit\vleB] \n"
"keyB1=valueB1\n"
))
]}.

syntax_error_title_test_() ->
%% TODO: Erlang 17 lost the ability to correctly report line numbers from errors.
%% Put the numbers back in some day when the fix is released
Expand Down Expand Up @@ -464,7 +464,7 @@ syntax_error_title_test_() ->
parse("[title]\n"
" ;comment\n"))
]}.

syntax_error_property_test_() ->
{setup,
fun setup/0,
Expand All @@ -481,7 +481,7 @@ syntax_error_property_test_() ->
parse("[title]\n"
"key;comment=value\n"))
]}.

dup_title_test_() ->
{setup,
fun setup/0,
Expand All @@ -495,7 +495,7 @@ dup_title_test_() ->
"keyB1=valueB1\n"
))
]}.

dup_key_test_() ->
{setup,
fun setup/0,
Expand Down Expand Up @@ -575,3 +575,23 @@ is_section_test_() ->
end}
]
}.

unicode_test_() ->
{setup,
fun setup/0,
fun teardown/1,
[
?_assertEqual({ok, [
{title, [{key1, <<"\xD1\x8E\xD0\xBD\xD0\xB8\xD0\xBA\xD0\xBE\xD0\xB4">>}]}
]},
parse(
"[title]\n"
"key1= \xD1\x8E\xD0\xBD\xD0\xB8\xD0\xBA\xD0\xBE\xD0\xB4 \n"
)),
?_assertEqual({ok, [
{title, [{key1, <<"\xD1\x8E\xD0\xBD\xD0\xB8\xD0\xBA\xD0\xBE\xD0\xB4">>}]}
]},
parse(
<<91,116,105,116,108,101,93,10,107,101,121,49,61,209,142,208,189,208,184,208,186,208,190,208,180,10>>
))
]}.

0 comments on commit 4f5517d

Please sign in to comment.