commit:962952a442b74a5d5fe365f77ab5481bc3cd3eba
author:Chip Black
committer:Chip Black
date:Sun Jan 16 06:08:22 2011 -0600
parents:e476507780c8d223365fadf59197ea7841848d3d
tags must be preceeded by whitespace or start at the beginning of the record
diff --git a/config.h b/config.h
line changes: +3/-0
index 9a16246..b363206
--- a/config.h
+++ b/config.h
@@ -10,4 +10,7 @@
 #define RECORDS_PER_SEGMENT 65536
 #define MAX_RECORD_SIZE 65535  /* No greater than 65535 */
 
+#define MAX_TAG_LENGTH 64
+#define MAX_TAGS_PER_RECORD 1024
+
 #endif //_CONFIG_H

diff --git a/database/tags.c b/database/tags.c
line changes: +8/-6
index 8386705..a28df02
--- a/database/tags.c
+++ b/database/tags.c
@@ -14,20 +14,19 @@
 #include "util.h"
 #include "config.h"
 
-#define MAX_TAG_LENGTH 64
-#define MAX_TAGS 1024
-
 #define TAG_CHAR(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-' || c == '_')
+#define WHITESPACE(c) (c == ' ' || c == '\t' || c == '\n' || c == '\r')
 
 int tag_scan(const char *author, const char *data, int len, uint64_t record) {
-	char *taglist[MAX_TAGS];
+	char *taglist[MAX_TAGS_PER_RECORD];
+	char last_char = ' ';
 	int n_tags = 0;
 	int i, j;
 
 	for (i = 0; i < len; i++) {
 tag_scan_start:
-		if (data[i] == '#' || data[i] == '@') {
-			if (n_tags == MAX_TAGS) {
+		if (WHITESPACE(last_char) && (data[i] == '#' || data[i] == '@')) {
+			if (n_tags == MAX_TAGS_PER_RECORD) {
 				fprintf(stderr, "Too many tags in message\n");
 				break;
 			}
@@ -43,14 +42,17 @@ tag_scan_start:
 				if (!strncmp(tag, taglist[j], MAX_TAG_LENGTH)) {
 					// We already have this tag.  Start over.
 					free(tag);
+					last_char = data[i-1];
 					goto tag_scan_start;
 				}
 			}
 			taglist[n_tags] = tag;
 			n_tags++;
+			last_char = data[i-1];
 			// We goto here so i doesn't get incremented
 			goto tag_scan_start;
 		}
+		last_char = data[i];
 	}
 
 	for (i = 0; i < n_tags; i++) {