Skip to content

Commit

Permalink
fix heredoc parsing
Browse files Browse the repository at this point in the history
See-also: SimonKagstrom#457
Signed-off-by: Mattéo Rossillol‑‑Laruelle <[email protected]>
  • Loading branch information
beatussum committed Jul 31, 2024
1 parent a39874f commit a03bf8d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/engines/bash-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,17 @@ class BashEngine : public ScriptEngineBase
if (!arithmeticActive && s.find("let ") != 0 && s.find("$((") == std::string::npos
&& s.find("))") == std::string::npos && heredocStart != std::string::npos)
{
// Skip << and remove spaces before and after "EOF"
heredocMarker = trim_string(s.substr(heredocStart + 2, s.size()));
// Skip <<
heredocMarker = s.substr(heredocStart + 2, s.size());

if (heredocMarker[0] == '-')
{
// '-' marks tab-suppression in heredoc
heredocMarker = heredocMarker.substr(1);
}

// Remove spaces before and after "EOF"
heredocMarker = trim_string(heredocMarker);

// Make sure the heredoc marker is a word
for (unsigned int i = 0; i < heredocMarker.size(); i++)
Expand All @@ -769,12 +778,6 @@ class BashEngine : public ScriptEngineBase
}
}

if (heredocMarker[0] == '-')
{
// '-' marks tab-suppression in heredoc
heredocMarker = heredocMarker.substr(1);
}

if (heredocMarker.length() > 2 && (heredocMarker[0] == '"' || heredocMarker[0] == '\'')
&& heredocMarker[0] == heredocMarker[heredocMarker.length() - 1])
{
Expand Down

0 comments on commit a03bf8d

Please sign in to comment.