Shell: Do not parse history events in scripts

That makes no sense!
This commit is contained in:
AnotherTest 2021-03-05 16:14:53 +03:30 committed by Andreas Kling
parent cad7865ad1
commit a303b69caa
Notes: sideshowbarker 2024-07-18 21:39:50 +09:00
4 changed files with 11 additions and 9 deletions

View File

@ -1118,7 +1118,7 @@ RefPtr<AST::Node> Parser::parse_expression()
return read_concat(create<AST::CastToList>(move(list))); // Cast To List
}
if (starting_char == '!') {
if (starting_char == '!' && m_in_interactive_mode) {
if (auto designator = parse_history_designator())
return designator;
}

View File

@ -37,8 +37,9 @@ namespace Shell {
class Parser {
public:
Parser(StringView input)
Parser(StringView input, bool interactive = false)
: m_input(move(input))
, m_in_interactive_mode(interactive)
{
}
@ -163,6 +164,7 @@ private:
Vector<char> m_extra_chars_not_allowed_in_barewords;
bool m_is_in_brace_expansion_spec { false };
bool m_continuation_controls_allowed { false };
bool m_in_interactive_mode { false };
};
#if 0

View File

@ -562,7 +562,7 @@ int Shell::run_command(const StringView& cmd, Optional<SourcePosition> source_po
if (cmd.is_empty())
return 0;
auto command = Parser(cmd).parse();
auto command = Parser(cmd, m_is_interactive).parse();
if (!command)
return 0;
@ -1289,7 +1289,7 @@ void Shell::add_entry_to_cache(const String& entry)
void Shell::highlight(Line::Editor& editor) const
{
auto line = editor.line();
Parser parser(line);
Parser parser(line, m_is_interactive);
auto ast = parser.parse();
if (!ast)
return;
@ -1300,7 +1300,7 @@ Vector<Line::CompletionSuggestion> Shell::complete()
{
auto line = m_editor->line(m_editor->cursor());
Parser parser(line);
Parser parser(line, m_is_interactive);
auto ast = parser.parse();
@ -1562,7 +1562,7 @@ bool Shell::has_history_event(StringView source)
bool has_history_event { false };
} visitor;
Parser { source }.parse()->visit(visitor);
Parser { source, true }.parse()->visit(visitor);
return visitor.has_history_event;
}

View File

@ -128,8 +128,8 @@ public:
RefPtr<Line::Editor> editor() const { return m_editor; }
struct LocalFrame {
LocalFrame(const String& name, HashMap<String, RefPtr<AST::Value>> variables)
: name(name)
LocalFrame(String name, HashMap<String, RefPtr<AST::Value>> variables)
: name(move(name))
, local_variables(move(variables))
{
}
@ -243,7 +243,7 @@ public:
return err;
}
void possibly_print_error() const;
bool is_control_flow(ShellError error)
static bool is_control_flow(ShellError error)
{
switch (error) {
case ShellError::InternalControlFlowBreak: