aboutsummaryrefslogtreecommitdiffstats
path: root/lib/misc.c
diff options
context:
space:
mode:
authordequis <dx@dxzone.com.ar>2014-07-24 00:51:07 -0300
committerdequis <dx@dxzone.com.ar>2014-07-24 00:51:07 -0300
commit269580c6302a677e07176494bd314c7e2a8f488f (patch)
tree393145104686ce5468d558c29a451a19677bf91d /lib/misc.c
parent1783ab6964c9a8ffc3488bb5243f0b15858f4e74 (diff)
Add limit param to split_command_parts(), fix twitter quotes bug
Only took me a few months to write. I even added a test case.
Diffstat (limited to 'lib/misc.c')
-rw-r--r--lib/misc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/misc.c b/lib/misc.c
index 49c4aa5d..2506e291 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -681,7 +681,7 @@ int md5_verify_password( char *password, char *hash )
/* Split commands (root-style, *not* IRC-style). Handles "quoting of"
white\ space in 'various ways'. Returns a NULL-terminated static
char** so watch out with nested use! Definitely not thread-safe. */
-char **split_command_parts( char *command )
+char **split_command_parts( char *command, int limit )
{
static char *cmd[IRC_MAX_ARGS+1];
char *s, q = 0;
@@ -691,11 +691,12 @@ char **split_command_parts( char *command )
cmd[0] = command;
k = 1;
for( s = command; *s && k < IRC_MAX_ARGS; s ++ )
+ {
if( *s == ' ' && !q )
{
*s = 0;
while( *++s == ' ' );
- if( *s == '"' || *s == '\'' )
+ if( k != limit && (*s == '"' || *s == '\'') )
{
q = *s;
s ++;
@@ -703,6 +704,9 @@ char **split_command_parts( char *command )
if( *s )
{
cmd[k++] = s;
+ if (limit && k > limit) {
+ break;
+ }
s --;
}
else
@@ -721,6 +725,7 @@ char **split_command_parts( char *command )
{
q = *s = 0;
}
+ }
/* Full zero-padding for easier argc checking. */
while( k <= IRC_MAX_ARGS )