浏览代码

Spreadsheet: Do not assume that user input has balanced parenthesis

Otherwise people with broken paren keys, or people with entertaining
ideas like "=9\b)" will cause an assert to trip.
Fixes #5909.
AnotherTest 4 年之前
父节点
当前提交
fef165f1d2
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      Userland/Applications/Spreadsheet/JSIntegration.cpp

+ 6 - 1
Userland/Applications/Spreadsheet/JSIntegration.cpp

@@ -64,6 +64,10 @@ Optional<FunctionAndArgumentIndex> get_function_and_argument_index(StringView so
         case JS::TokenType::ParenClose:
         case JS::TokenType::ParenClose:
             previous_was_identifier = false;
             previous_was_identifier = false;
             if (open_parens_since_last_commit == 0) {
             if (open_parens_since_last_commit == 0) {
+                if (state.is_empty() || names.is_empty()) {
+                    // JS Syntax error.
+                    break;
+                }
                 state.take_last();
                 state.take_last();
                 names.take_last();
                 names.take_last();
                 break;
                 break;
@@ -73,7 +77,8 @@ Optional<FunctionAndArgumentIndex> get_function_and_argument_index(StringView so
         case JS::TokenType::Comma:
         case JS::TokenType::Comma:
             previous_was_identifier = false;
             previous_was_identifier = false;
             if (open_parens_since_last_commit == 0 && open_curlies_and_brackets_since_last_commit == 0) {
             if (open_parens_since_last_commit == 0 && open_curlies_and_brackets_since_last_commit == 0) {
-                state.last()++;
+                if (!state.is_empty())
+                    state.last()++;
                 break;
                 break;
             }
             }
             break;
             break;