Fixes for ticket #3052: some commands started triggering when extra text is supposed to suppress them

Regressions caused by bad refactoring in commit 21feac3bea.
Test cases in tests/CommandInterpreterTest.php were made against the pre-refactoring code, and now check out with the fixed code.
Failures were caused by not changing logic structure when moving from multiple exit points (each if point would return directly with a null or an object) to setting a result variable and then falling through to a common exit point. Without the if statements being restructured, the result variable would just get overridden by the next case.
This commit is contained in:
Brion Vibber 2011-02-21 11:42:32 -08:00
parent 11e033f05c
commit eb7e3ee528

View File

@ -42,8 +42,9 @@ class CommandInterpreter
case 'help':
if ($arg) {
$result = null;
}
} else {
$result = new HelpCommand($user);
}
break;
case 'login':
if ($arg) {
@ -120,50 +121,52 @@ class CommandInterpreter
case 'join':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new JoinCommand($user, $other);
}
}
break;
case 'drop':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new DropCommand($user, $other);
}
}
break;
case 'follow':
case 'sub':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new SubCommand($user, $other);
}
}
break;
case 'leave':
case 'unsub':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new UnsubCommand($user, $other);
}
}
break;
case 'get':
case 'last':
@ -207,68 +210,74 @@ class CommandInterpreter
case 'rd':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new RepeatCommand($user, $other);
}
}
break;
case 'whois':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new WhoisCommand($user, $other);
}
}
break;
case 'fav':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new FavCommand($user, $other);
}
}
break;
case 'nudge':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new NudgeCommand($user, $other);
}
}
break;
case 'stats':
if ($arg) {
$result = null;
}
} else {
$result = new StatsCommand($user);
}
break;
case 'invite':
if (!$arg) {
$result = null;
}
} else {
list($other, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
} else {
$result = new InviteCommand($user, $other);
}
}
break;
case 'track':
if (!$arg) {
$result = null;
}
} else {
list($word, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
@ -277,11 +286,12 @@ class CommandInterpreter
} else {
$result = new TrackCommand($user, $word);
}
}
break;
case 'untrack':
if (!$arg) {
$result = null;
}
} else {
list($word, $extra) = $this->split_arg($arg);
if ($extra) {
$result = null;
@ -290,13 +300,15 @@ class CommandInterpreter
} else {
$result = new UntrackCommand($user, $word);
}
}
break;
case 'tracks':
case 'tracking':
if ($arg) {
$result = null;
}
} else {
$result = new TrackingCommand($user);
}
break;
default:
$result = false;