[mw-devel] MW3 r1105 - trunk/src

psycodom at sucs.org psycodom at sucs.org
Sun Nov 15 18:38:54 GMT 2009


Author: psycodom
Date: 2009-11-15 18:38:54 +0000 (Sun, 15 Nov 2009)
New Revision: 1105

Modified:
   trunk/src/gags.c
   trunk/src/log.c
   trunk/src/strings.c
   trunk/src/strings.h
Log:
fixes a bug which meant foo.coma foo.command etc. were mathced as uris

cleaned up the mwuri code to ignore colour sequences which should stop it 
breaking the webpage with the escape char and also pick up uris which were
started with a colour sequence or have a colour sequence in them

moved strip_colours from gag.c to strings.c now it is used by log.c as well as
 gag.c and made it safe for use with strings containing utf8 chars.



Modified: trunk/src/gags.c
===================================================================
--- trunk/src/gags.c	2009-11-13 18:24:47 UTC (rev 1104)
+++ trunk/src/gags.c	2009-11-15 18:38:54 UTC (rev 1105)
@@ -9,29 +9,6 @@
   GAG SUPPORT ROUTINES - USEFUL THINGIES
 ****************************************************************/
 
-/* returns a new string without any colour codes in */
-char *strip_colours(char *text)
-{
-	char *new;
-	int i, j, len;
-
-	len = strlen(text);
-	new = malloc(sizeof(char) * (len+1));
-	i=0;
-	j=0;
-	while (i<len)
-	{
-		if (text[i]==033)
-		{
-			i+=3;
-			continue;
-		}
-		new[j++]=text[i++];
-	}
-	new[j]=0;
-	return(new);
-}
-
 /* given two strings of the same length, will copy colour codes from one to the other */
 char *merge_colours(char *in, char *old)
 {

Modified: trunk/src/log.c
===================================================================
--- trunk/src/log.c	2009-11-13 18:24:47 UTC (rev 1104)
+++ trunk/src/log.c	2009-11-15 18:38:54 UTC (rev 1105)
@@ -75,7 +75,8 @@
 	{"^http://", 		REG_ICASE, NULL, URL,    0},
 	{"^https://", 		REG_ICASE, NULL, URL,    0},
 	{"^www\\.", 		REG_ICASE, NULL, URL,    0},
-	{"^[[:alnum:]_.-]+\\.(com|org|net|gov|(co|org|net|gov)\\.uk)", 	REG_ICASE|REG_EXTENDED, NULL, URL,    0},
+	{"^[[:alnum:]_.-]+\\.(com|org|net|gov|(co|org|net|gov)\\.uk)$", 	REG_ICASE|REG_EXTENDED, NULL, URL,    0},
+	{"^[[:alnum:]_.-]+\\.(com|org|net|gov|(co|org|net|gov)\\.uk)/", 	REG_ICASE|REG_EXTENDED, NULL, URL,    0},
 	{"[+-]nsfw", 		REG_ICASE, NULL, FLAG,   URLFLAG_NSFW},
 	{"(nsfw)", 		REG_ICASE, NULL, FLAG,   URLFLAG_NSFW},
 	{"^[+-]anon$", 		REG_ICASE, NULL, FLAG,   URLFLAG_ANON},
@@ -112,7 +113,7 @@
 
 void catchuri(const char *what)
 {
-	char *text = strdup(what);
+	char *text = strip_colours(what);
 	char *token;
 	/* kludge, find at most 20 URLs */
 	char *foundurl[20];

Modified: trunk/src/strings.c
===================================================================
--- trunk/src/strings.c	2009-11-13 18:24:47 UTC (rev 1104)
+++ trunk/src/strings.c	2009-11-15 18:38:54 UTC (rev 1105)
@@ -424,3 +424,51 @@
 
 	printf("%s", szText);
 }
+
+/* returns a new string without any mw colour codes in */
+char *strip_colours(const char *text)
+{
+	char *new;
+	int i, j, len, k;
+
+	len = strlen(text);
+	new = malloc(sizeof(char) * (len+1));
+	i=0;
+	j=0;
+	while (i<len)
+	{
+		if (text[i]==033)
+		{
+			i++;
+			k=0;
+			//utf8 safe way to skip the next two chars
+			//we only need this in case someone is mean enough to try using something like
+			// [ESC]r£ as a colour sequence which would previously have us remove the first 
+			// byte of the utf8 sequence leaving us with an invalid char.
+			while(i<len && k<2)
+			{
+				if(((unsigned char)text[i] & 192)==192 )
+				{
+					// skip char is the first byte of a utf8 sequence
+					i++;
+					while( ((unsigned char)text[i] & 192) == 128 && i<len)
+					{
+						//skip all utf8 continuation bytes
+						i++;
+					}
+				}
+				else
+				{
+					// char was ascii so we can just skip it.
+					i++;
+				}
+				k++;
+			}
+			
+			continue;
+		}
+		new[j++]=text[i++];
+	}
+	new[j]=0;
+	return(new);
+}

Modified: trunk/src/strings.h
===================================================================
--- trunk/src/strings.h	2009-11-13 18:24:47 UTC (rev 1104)
+++ trunk/src/strings.h	2009-11-15 18:38:54 UTC (rev 1105)
@@ -26,3 +26,4 @@
 int stringcmp(const char *a, const char *b, int n);
 
 void escprintf(char *szFormat, ...);
+char *strip_colours(const char *text);




More information about the mw-devel mailing list