From 488a588aea080767896e282f995a16fc954cf352 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 9 Dec 2021 11:56:40 -0800 Subject: [PATCH] Detect shebang more precisely and simplify erase code --- CLI/FileUtils.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/CLI/FileUtils.cpp b/CLI/FileUtils.cpp index ae326f3e..7673492a 100644 --- a/CLI/FileUtils.cpp +++ b/CLI/FileUtils.cpp @@ -67,16 +67,9 @@ std::optional readFile(const std::string& name) if (read != size_t(length)) return std::nullopt; - // Skip first line if it's a comment - if (length != 0 && result[0] == '#') - { - auto newLine = result.find('\n'); - - if (newLine != std::string::npos) - result.erase(0, newLine); - else - result.clear(); - } + // Skip first line if it's a shebang + if (length > 2 && result[0] == '#' && result[1] == '!') + result.erase(0, result.find('\n')); return result; }