From 3fefa52be62534ee11db0623df0319106e7e557a Mon Sep 17 00:00:00 2001 From: Emily Pillmore Date: Tue, 13 Feb 2024 13:56:55 -0700 Subject: [PATCH] fix enforce-pact-version decimal parser (#1334) * fix enforce-pact-version decimal parser * Update tests/pact/versions.repl Co-authored-by: rsoeldner * Update tests/pact/versions.repl Co-authored-by: rsoeldner --------- Co-authored-by: rsoeldner --- src/Pact/Native.hs | 10 ++++++---- tests/pact/versions.repl | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 tests/pact/versions.repl diff --git a/src/Pact/Native.hs b/src/Pact/Native.hs index eb9b2c45d..4a9f39e2b 100644 --- a/src/Pact/Native.hs +++ b/src/Pact/Native.hs @@ -1238,21 +1238,23 @@ enforceVersion i as = do pactVersion' <- if cond then pure compatVersion else checkNonLocalAllowed i $> pactVersion case as of - [TLitString minVersion] -> doMin minVersion pactVersion' >> return (toTerm True) + [TLitString minVersion] -> doMin minVersion pactVersion' $> toTerm True [TLitString minVersion,TLitString maxVersion] -> - doMin minVersion pactVersion' >> doMax maxVersion pactVersion' >> return (toTerm True) + doMin minVersion pactVersion' >> doMax maxVersion pactVersion' $> toTerm True _ -> argsError i as where compatVersion :: Text compatVersion = "4.2.1" doMin = doMatch "minimum" (>) (<) doMax = doMatch "maximum" (<) (>) - doMatch msg failCmp succCmp fullV pactVersion' = + doMatch msg failCmp succCmp fullV pactVersion' = do foldM_ matchPart False $ zip (T.splitOn "." pactVersion') (T.splitOn "." fullV) where - parseNum orgV s = case AP.parseOnly (AP.many1 AP.digit) s of + parseNum :: Text -> Text -> Eval e Integer + parseNum orgV s = case AP.parseOnly AP.decimal s of Left _ -> evalError' i $ "Invalid version component: " <> pretty (orgV,s) Right v -> return v + matchPart True _ = return True matchPart _ (pv,mv) = do pv' <- parseNum pactVersion' pv diff --git a/tests/pact/versions.repl b/tests/pact/versions.repl new file mode 100644 index 000000000..0f914d58a --- /dev/null +++ b/tests/pact/versions.repl @@ -0,0 +1,26 @@ + + +(expect + "pact version bounds work for current pact version" + true + (enforce-pact-version "3.0.0" "6.0.0")) + +(expect + "enforce-pact-version works for current pact version" + true + (enforce-pact-version (pact-version))) + +(expect-failure + "pact version bounds fail for current version if wrong bounds" + (enforce-pact-version "6.0.0" "100.0.0")) + +;; regression #1327 +(expect + "enforce-pact-version succeeds for current version if lower bound set" + true + (enforce-pact-version "1.0.0")) + +(expect + "enforce-pact-version succeeds (double digit regression)" + true + (enforce-pact-version "3.0000.0" "88.420.0"))