From 9bbe0874ce31a3507a124c71563e825a53abb72b Mon Sep 17 00:00:00 2001 From: Dillon Kearns Date: Tue, 30 Mar 2021 17:50:45 -0700 Subject: [PATCH] Don't allow arbitrary glob patterns, only literals, in zeroOrMore. --- src/Glob.elm | 9 +++------ tests/GlobTests.elm | 17 ++++++----------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Glob.elm b/src/Glob.elm index dbb6706b..5d464830 100644 --- a/src/Glob.elm +++ b/src/Glob.elm @@ -114,14 +114,11 @@ oneOf ( defaultMatch, otherMatchers ) = ) -optional : List (GlobMatcher a) -> GlobMatcher (Maybe String) -optional matchers = +zeroOrMore : List String -> GlobMatcher (Maybe String) +zeroOrMore matchers = GlobMatcher ("*(" - ++ (matchers - |> List.map (\(GlobMatcher pattern _) -> pattern) - |> String.join "|" - ) + ++ (matchers |> String.join "|") ++ ")" ) (Dynamic diff --git a/tests/GlobTests.elm b/tests/GlobTests.elm index 105e2aa8..3df48fa1 100644 --- a/tests/GlobTests.elm +++ b/tests/GlobTests.elm @@ -46,7 +46,7 @@ all = } , test "optional group - no match" <| \() -> - oneOrMoreGlob + zeroOrMoreGlob |> expect -- test/a/x.js -- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L42 @@ -56,7 +56,7 @@ all = } , test "optional group - single match" <| \() -> - oneOrMoreGlob + zeroOrMoreGlob |> expect -- test/ab/x.js -- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L44 @@ -66,7 +66,7 @@ all = } , test "optional group - multiple matches" <| \() -> - oneOrMoreGlob + zeroOrMoreGlob |> expect -- test/aba/x.js -- https://github.com/micromatch/micromatch/blob/fe4858b0c63b174fd3ae22674db39119b8fa4392/test/api.capture.js#L45 @@ -77,16 +77,11 @@ all = ] -oneOrMoreGlob : Glob.Glob (Maybe String) -oneOrMoreGlob = +zeroOrMoreGlob : Glob.Glob (Maybe String) +zeroOrMoreGlob = Glob.init identity |> Glob.drop (Glob.literal "test/a") - |> Glob.keep - (Glob.optional - [ Glob.literal "a" - , Glob.literal "b" - ] - ) + |> Glob.keep (Glob.zeroOrMore [ "a", "b" ]) |> Glob.drop (Glob.literal "/x.js")