[asterisk-commits] jrose: branch 1.8 r313860 - in /branches/1.8: ./ main/cli.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 15 10:08:21 CDT 2011


Author: jrose
Date: Fri Apr 15 10:08:05 2011
New Revision: 313860

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=313860
Log:
Merged revisions 313859 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.6.2

........
  r313859 | jrose | 2011-04-15 09:58:37 -0500 (Fri, 15 Apr 2011) | 10 lines
  
  Fix a Tab Completion bug that occurs due to multiple matches on a substring.
  
  Makes word_match function in cli.c repeat a search for a command string until
  a proper match is found or the string is searched to the last point.
  
  (closes issue #17494)
  Reported by: ffossard
  
  Review: https://reviewboard.asterisk.org/r/1180/
........

Modified:
    branches/1.8/   (props changed)
    branches/1.8/main/cli.c

Propchange: branches/1.8/
------------------------------------------------------------------------------
Binary property 'branch-1.6.2-merged' - no diff available.

Modified: branches/1.8/main/cli.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/cli.c?view=diff&rev=313860&r1=313859&r2=313860
==============================================================================
--- branches/1.8/main/cli.c (original)
+++ branches/1.8/main/cli.c Fri Apr 15 10:08:05 2011
@@ -1879,20 +1879,30 @@
 		return -1;
 	if (!strchr(cli_rsvd, cli_word[0])) /* normal match */
 		return (strcasecmp(cmd, cli_word) == 0) ? 1 : -1;
-	/* regexp match, takes [foo|bar] or {foo|bar} */
 	l = strlen(cmd);
 	/* wildcard match - will extend in the future */
 	if (l > 0 && cli_word[0] == '%') {
 		return 1;	/* wildcard */
 	}
+
+	/* Start a search for the command entered against the cli word in question */
 	pos = strcasestr(cli_word, cmd);
-	if (pos == NULL) /* not found, say ok if optional */
-		return cli_word[0] == '[' ? 0 : -1;
-	if (pos == cli_word)	/* no valid match at the beginning */
-		return -1;
-	if (strchr(cli_rsvd, pos[-1]) && strchr(cli_rsvd, pos[l]))
-		return 1;	/* valid match */
-	return -1;	/* not found */
+	while (pos) {
+
+		/*
+		 *Check if the word matched with is surrounded by reserved characters on both sides
+		 * and isn't at the beginning of the cli_word since that would make it check in a location we shouldn't know about.
+		 * If it is surrounded by reserved chars and isn't at the beginning, it's a match.
+		 */
+		if (pos != cli_word && strchr(cli_rsvd, pos[-1]) && strchr(cli_rsvd, pos[l])) {
+			return 1;	/* valid match */
+		}
+
+		/* Ok, that one didn't match, strcasestr to the next appearance of the command and start over.*/
+		pos = strcasestr(pos + 1, cmd);
+	}
+	/* If no matches were found over the course of the while loop, we hit the end of the string. It's a mismatch. */
+	return -1;
 }
 
 /*! \brief if word is a valid prefix for token, returns the pos-th




More information about the asterisk-commits mailing list