From d6bb8fc0d8aa40e72b2b894b16d7eacdafcf94a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Moritz=20R=C3=B6hrich?= <moritz@ildefons.de>
Date: Sun, 14 Feb 2021 19:13:29 +0100
Subject: [PATCH] Error on backslash in comment   #2132

- Report error in case of a backspace in a comment

Backspaces in comments are no good. In most cases they are the result of
commenting out a longer line, that was broken down. This usually results
in the shell treating the following lines as their own commands on their
own lines instead of as parts of the longer, broken down line.
---
 src/ShellCheck/Parser.hs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ShellCheck/Parser.hs b/src/ShellCheck/Parser.hs
index 03865af..a999b23 100644
--- a/src/ShellCheck/Parser.hs
+++ b/src/ShellCheck/Parser.hs
@@ -1039,9 +1039,14 @@ readComment = do
     unexpecting "shellcheck annotation" readAnnotationPrefix
     readAnyComment
 
+prop_readAnyComment = isOk readAnyComment "# Comment"
+prop_readAnyComment1 = not $ isOk readAnyComment "# Comment \\\n"
 readAnyComment = do
     char '#'
-    many $ noneOf "\r\n"
+    comment <- many $ noneOf "\\\r\n"
+    bs <- many $ oneOf "\\"
+    unless (null bs) (fail "Backslash in or directly after comment")
+    return comment
 
 prop_readNormalWord = isOk readNormalWord "'foo'\"bar\"{1..3}baz$(lol)"
 prop_readNormalWord2 = isOk readNormalWord "foo**(foo)!!!(@@(bar))"