Skip to content

Commit 4feef83

Browse files
committed
fix: resolved a crash in command parsing
1 parent f5cacef commit 4feef83

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/endstone/core/command/minecraft_command_adapter.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ std::string_view parseNode(const CommandRegistry::ParseToken &root)
9494

9595
// Otherwise:
9696
const auto &child = *root.child;
97-
auto *begin = findFirstWithText(&child)->text;
97+
const auto *begin = findFirstWithText(&child);
98+
if (!begin) {
99+
return "";
100+
}
98101

99102
// (1) If this node has no next sibling, it's the last argument: consume all remaining text until the end
100103
if (!root.next) {
101-
const auto view = rstrip(begin);
104+
const auto view = rstrip(begin->text);
102105
if (child.type == CommandRegistry::HardNonTerminal::Id) {
103106
return removeQuotes(view);
104107
}
@@ -107,8 +110,16 @@ std::string_view parseNode(const CommandRegistry::ParseToken &root)
107110

108111
// (2) Otherwise, find the start of the next argument and extract the substring between begin and end, then trim
109112
// trailing whitespace.
110-
auto *end = findFirstWithText(root.next.get())->text;
111-
const auto view = rstrip({begin, end});
113+
const auto *end = findFirstWithText(root.next.get());
114+
if (!end) {
115+
const auto view = rstrip(begin->text);
116+
if (child.type == CommandRegistry::HardNonTerminal::Id) {
117+
return removeQuotes(view);
118+
}
119+
return view;
120+
}
121+
122+
const auto view = rstrip({begin->text, end->text});
112123
if (child.type == CommandRegistry::HardNonTerminal::Id) {
113124
return removeQuotes(view);
114125
}

0 commit comments

Comments
 (0)