From 7a121b63e2bc1e942dd68a7b4976e83fde7d286e Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Thu, 7 Mar 2024 06:14:00 +0100
Subject: chore: fix parsing special characters

---
 src/Process/Shell.hs | 4 +++-
 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 $#|]
-- 
cgit v1.2.3