From c43616cf3afe84ba8f0e0f1a1fdaf4c425e51d37 Mon Sep 17 00:00:00 2001 From: Ted Kornish Date: Thu, 1 Mar 2018 11:31:29 -0800 Subject: [PATCH] Don't parse hyphens in Chars() unless escaped --- parser.go | 2 ++ parser_test.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/parser.go b/parser.go index a612857..7530b3d 100644 --- a/parser.go +++ b/parser.go @@ -181,6 +181,8 @@ func parseMatcher(matcher string) (alphabet string, ranges [][]rune) { } } else if i+1 < len(runes) && runes[i] == '\\' { alphabet += string(runes[i+1]) + } else if runes[i] == '-' { + continue } else { alphabet += string(runes[i]) } diff --git a/parser_test.go b/parser_test.go index b2e698c..2fdaafe 100644 --- a/parser_test.go +++ b/parser_test.go @@ -114,7 +114,7 @@ func TestChars(t *testing.T) { t.Run("unescaped hyphen", func(t *testing.T) { node, ps := runParser("19-", Chars("0-9")) require.Equal(t, "19", node.Token) - require.Equal(t, 2, ps.Pos) + require.Equal(t, "-", ps.Get()) // hyphen shouldn't have been parsed require.False(t, ps.Errored()) })