Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <fstream>
#include <string>
#include <regex>
#include <boost/regex.hpp>
#ifndef _WIN32
# include <glob.h>
#endif
Expand Down Expand Up @@ -301,10 +301,13 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
while (std::getline(stream, line) && !line.empty() && commentChars.find(line[0]) != std::string::npos) {
line = chomp(line);

std::smatch match;
static const auto nixLineRegex =
boost::regex("^#!\\s*nix(:? |$)(.*)$", boost::regex_constants::optimize);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. (:? seems like a bug -> (?:?


boost::smatch match;
// We match one space after `nix` so that we preserve indentation.
// No space is necessary for an empty line. An empty line has basically no effect.
if (std::regex_match(line, match, std::regex("^#!\\s*nix(:? |$)(.*)$")))
if (boost::regex_match(line, match, nixLineRegex))
shebangContent += std::string_view{match[2].first, match[2].second} + "\n";
}
for (const auto & word : parseShebangContent(shebangContent)) {
Expand Down
Loading