Skip to content
Snippets Groups Projects
Verified Commit 2e43bd55 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fixes bug that could cause crashes

When using an alias with $i.. parameter without providing enough params
it would expand to subList(i, params.size). If i was larger than the
number of parameters, this would violate an invariant in subList and
cause a crash.

This bug was fixed, additionally the code now matches the functionality
of the desktop version, further bugs introduced while porting the code
have been fixed.
parent 3d3d4e3a
No related branches found
No related tags found
No related merge requests found
Pipeline #304 passed
...@@ -115,7 +115,7 @@ class AliasManager constructor( ...@@ -115,7 +115,7 @@ class AliasManager constructor(
if (msg.startsWith("//")) if (msg.startsWith("//"))
msg = msg.substring(1) // "//asdf" is transformed to "/asdf" msg = msg.substring(1) // "//asdf" is transformed to "/asdf"
else if (msg.startsWith("/ ")) else if (msg.startsWith("/ "))
msg.substring(2) // "/ /asdf" is transformed to "/asdf" msg = msg.substring(2) // "/ /asdf" is transformed to "/asdf"
msg = "/SAY $msg" // make sure we only send proper commands to the core msg = "/SAY $msg" // make sure we only send proper commands to the core
} else { } else {
// check for aliases // check for aliases
...@@ -149,17 +149,13 @@ class AliasManager constructor( ...@@ -149,17 +149,13 @@ class AliasManager constructor(
for (match in paramRange.findAll(command)) { for (match in paramRange.findAll(command)) {
val start = match.groups[1]?.value?.toIntOrNull() ?: -1 val start = match.groups[1]?.value?.toIntOrNull() ?: -1
val replacement: String val replacement: String
val end = match.groups[2]?.value?.toIntOrNull() ?: params.size
// $1.. would be "arg1 and all following" // $1.. would be "arg1 and all following"
replacement = if (match.groups[2]?.value.isNullOrEmpty()) { replacement = if (end < start) {
params.subList(start, params.size).joinToString(" ")
} else {
val end = match.groups[2]?.value?.toIntOrNull() ?: -1
if (end < start) {
"" ""
} else { } else {
params.subList(start, end).joinToString(" ") params.subList(start, end).joinToString(" ")
} }
}
command = command.substring(0, match.range.start) + replacement + command = command.substring(0, match.range.start) + replacement +
command.substring(match.range.endInclusive + 1) command.substring(match.range.endInclusive + 1)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment