diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-07 06:14:00 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-07 06:14:00 +0100 |
commit | 7a121b63e2bc1e942dd68a7b4976e83fde7d286e (patch) | |
tree | dcf2d63326c75975122172538bbf390b889625cf | |
parent | 88e897fa21d0de229700862b11761b8e33752dba (diff) |
chore: fix parsing special characters
-rw-r--r-- | src/Process/Shell.hs | 4 | ||||
-rw-r--r-- | test/Main.hs | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/Process/Shell.hs b/src/Process/Shell.hs index 6df6a4f..4b26512 100644 --- a/src/Process/Shell.hs +++ b/src/Process/Shell.hs @@ -142,7 +142,9 @@ sh = QuasiQuoter quoteExp undefined undefined undefined <* string "}'" ), do - Lit <$> takeWhile1P Nothing ((&&) <$> (/= '#') <*> (/= '\'')) + Lit <$> takeWhile1P Nothing ((&&) <$> (/= '#') <*> (/= '\'')), + do + Lit . (: []) <$> satisfy ((||) <$> (== '\'') <*> (== '#')) ] makeExp exprs = do diff --git a/test/Main.hs b/test/Main.hs index 0d00db3..71723c3 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -43,7 +43,7 @@ main = hspec do it "interpolates monadic expressions" do (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo -n '#{pure @IO x}'|] it "preserves argument order" do - (`shouldBe` "1 2") =<< let x = "1"; y = "2"; in [sh|echo -n '#{x}' '#{y}'|] + (`shouldBe` "1 2") =<< let x = "1"; y = "2" in [sh|echo -n '#{x}' '#{y}'|] describe "quoting" do it "preserves arguments" do (`shouldBe` "foo\\ bar") @@ -57,3 +57,8 @@ main = hspec do it "preserves empty arguments" do (`shouldBe` "''") =<< let x = "" in [sh|printf %q #{x}|] (`shouldBe` "''") =<< let x = "" in [sh|printf %q '#{x}'|] + describe "parsing" do + it "parses shell quotes" do + (`shouldBe` "foobar") =<< [sh|echo -n 'foobar'|] + it "parses double cross" do + (`shouldBe` "0") =<< [sh|echo -n $#|] |