diff --git a/.travis.yml b/.travis.yml index fb55c70..d54ddc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: erlang otp_release: - - 18.1 - - 18.0 - - 17.5 + - 21.1 + - 20.3 + - 19.3 sudo: false diff --git a/src/config_writer.erl b/src/config_writer.erl index 159437c..fb6ef14 100644 --- a/src/config_writer.erl +++ b/src/config_writer.erl @@ -31,7 +31,7 @@ save_to_file({{Section, Key}, Value}, File) -> Lines = re:split(OldFileContents, "\r\n|\n|\r|\032", [{return, list}]), SectionLine = "[" ++ Section ++ "]", - {ok, Pattern} = re:compile(["^(", Key, "\\s*=)|\\[[a-zA-Z0-9\.\_-]*\\]"]), + {ok, Pattern} = re:compile(["^(\\Q", Key, "\\E\\s*=)|\\[[a-zA-Z0-9\.\_-]*\\]"]), NewLines = process_file_lines(Lines, [], SectionLine, Pattern, Key, Value), NewFileContents = reverse_and_add_newline(strip_empty_lines(NewLines), []), diff --git a/test/config_tests.erl b/test/config_tests.erl index 2b78798..6282822 100644 --- a/test/config_tests.erl +++ b/test/config_tests.erl @@ -297,6 +297,20 @@ config_notifier_behaviour_test_() -> }. +config_key_has_regex_test_() -> + { + "Test key with regex can be compiled and written to file", + { + foreach, + fun setup/0, + fun teardown/1, + [ + fun should_handle_regex_patterns_in_key/0 + ] + } + }. + + config_access_right_test_() -> { "Test config file access right", @@ -318,6 +332,11 @@ should_write_config_to_file() -> ?assertEqual(ok, config:set("admins", "foo", "500", true)). +should_handle_regex_patterns_in_key() -> + ?assertEqual(ok, config:set("sect1", "pat||*", "true", true)), + ?assertEqual([{"pat||*", "true"}], config:get("sect1")). + + should_delete_config_from_file() -> ?assertEqual(ok, config:delete("admins", "foo", true)).