Kaynağa Gözat

External command fixes

CommandArguments.getWordsAsString now sanity checks its arguments
External /mode command now uses correct offset
All external commands are now passed the correct arguments
Fixes issue 3125

Change-Id: Ib546c03443ac51a1bb6b5d3d4b6a2204e04a8be1
Reviewed-on: http://gerrit.dmdirc.com/58
Reviewed-by: Gregory Holmes <greboid@dmdirc.com>
Tested-by: Gregory Holmes <greboid@dmdirc.com>
tags/0.6.3b1
Chris Smith 14 yıl önce
ebeveyn
işleme
bf590d89f8

+ 6
- 0
src/com/dmdirc/commandparser/CommandArguments.java Dosyayı Görüntüle

@@ -22,6 +22,9 @@
22 22
 
23 23
 package com.dmdirc.commandparser;
24 24
 
25
+import com.dmdirc.Precondition;
26
+import com.dmdirc.logger.Logger;
27
+
25 28
 import java.util.Arrays;
26 29
 import java.util.regex.Matcher;
27 30
 import java.util.regex.Pattern;
@@ -144,7 +147,10 @@ public class CommandArguments {
144 147
      * @param end The index of the last word to include
145 148
      * @return A String representation of the requested words
146 149
      */
150
+    @Precondition("Start index is less than or equal to end index")
147 151
     public String getWordsAsString(final int start, final int end) {
152
+        Logger.assertTrue(start <= end);
153
+
148 154
         final Pattern pattern = Pattern.compile("(\\S+\\s*){" + (start) + "}"
149 155
                 + "((\\S+\\s*){" + (end - start) + "}).*?");
150 156
         final Matcher matcher = pattern.matcher(line);

+ 2
- 2
src/com/dmdirc/commandparser/commands/channel/Mode.java Dosyayı Görüntüle

@@ -69,10 +69,10 @@ public final class Mode extends ChannelCommand implements IntelligentCommand,
69 69
     @Override
70 70
     public void execute(final InputWindow origin, final Server server,
71 71
             final String channel, final boolean isSilent, final CommandArguments args) {
72
-        if (args.getArguments().length == 1) {
72
+        if (args.getArguments().length == 0) {
73 73
             server.getParser().sendRawMessage("MODE " + channel);
74 74
         } else {
75
-            server.getParser().sendRawMessage("MODE " + channel + " " + args.getArgumentsAsString(1));
75
+            server.getParser().sendRawMessage("MODE " + channel + " " + args.getArgumentsAsString());
76 76
         }
77 77
     }
78 78
 

+ 2
- 1
src/com/dmdirc/commandparser/parsers/CommandParser.java Dosyayı Görüntüle

@@ -147,7 +147,8 @@ public abstract class CommandParser implements Serializable {
147 147
                     if (actCommand != null && actCommand.getValue() instanceof ExternalCommand) {
148 148
                         ((ExternalCommand) actCommand.getValue()).execute(
149 149
                                 origin, server, cargs[0], silent,
150
-                                new CommandArguments(args.getWordsAsString(2)));
150
+                                new CommandArguments(args.getCommandName()
151
+                                + " " + args.getWordsAsString(2)));
151 152
                         return;
152 153
                     }
153 154
                 }

Loading…
İptal
Kaydet