瀏覽代碼

Shell: Do not parse history events in scripts

That makes no sense!
AnotherTest 4 年之前
父節點
當前提交
a303b69caa
共有 4 個文件被更改,包括 11 次插入9 次删除
  1. 1 1
      Userland/Shell/Parser.cpp
  2. 3 1
      Userland/Shell/Parser.h
  3. 4 4
      Userland/Shell/Shell.cpp
  4. 3 3
      Userland/Shell/Shell.h

+ 1 - 1
Userland/Shell/Parser.cpp

@@ -1118,7 +1118,7 @@ RefPtr<AST::Node> Parser::parse_expression()
         return read_concat(create<AST::CastToList>(move(list))); // Cast To List
         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())
         if (auto designator = parse_history_designator())
             return designator;
             return designator;
     }
     }

+ 3 - 1
Userland/Shell/Parser.h

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

+ 4 - 4
Userland/Shell/Shell.cpp

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

+ 3 - 3
Userland/Shell/Shell.h

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