Skip to content

Commit

Permalink
Merge pull request #3 from operable/fix-comment-prefix-regex
Browse files Browse the repository at this point in the history
Anchor comment prefix regex to start of line
  • Loading branch information
easco authored Feb 26, 2017
2 parents f1072e2 + 9bdeb6e commit 17734a8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/configparser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ defmodule ConfigParser do
end

# Returns true if the line appears to be a comment
@hash_comment_regex ~r{#.*}
@semicolon_comment_regex ~r{;.*}
@hash_comment_regex ~r{^#.*}
@semicolon_comment_regex ~r{^;.*}

defp is_comment(line) do
String.strip(line) =~ @hash_comment_regex || String.strip(line) =~ @semicolon_comment_regex
Expand Down
7 changes: 6 additions & 1 deletion test/configparser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ defmodule ConfigParserTest do
[You can use comments]
# like this
; or this
# and also this
but not # like this
and also ; not this
# By default only in an empty line.
# Inline comments can be harmful because they prevent users
Expand Down Expand Up @@ -275,7 +278,9 @@ defmodule ConfigParserTest do
"spaces around the delimiter" => "obviously",
"spaces in keys" => "allowed", "spaces in values" => "allowed as well",
"you can also use" => "to delimit keys from values"},
"You can use comments" => %{}}} )
"You can use comments" => %{
"but not # like this" => nil,
"and also" => nil}}} )

end
end

0 comments on commit 17734a8

Please sign in to comment.