about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-04-09 15:12:56 -0400
committerJune McEnroe <june@causal.agency>2021-04-09 15:12:56 -0400
commit5edf949cb743e8da5e73aa2f98695c2dd370657f (patch)
treedc05d06d293a2af23857b8ab5e6da0b03240340f
parentExit on getopt failure (diff)
downloadbubger-5edf949cb743e8da5e73aa2f98695c2dd370657f.tar.gz
bubger-5edf949cb743e8da5e73aa2f98695c2dd370657f.zip
Remove unnecessary capture group in URL regex
That capture group actually makes the regex ambiguous, it seems,
since apparently some implementations backtrack to match the .
branch rather than the $ branch, leaving off a trailing character
from the second capture group. Regardless, that trailing capture
group is totally unnecessary and I don't know why it was there.
Diffstat (limited to '')
-rw-r--r--html.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/html.c b/html.c
index 77438a0..34ffb16 100644
--- a/html.c
+++ b/html.c
@@ -228,12 +228,12 @@ static void swap(char *a, char *b) {
 
 static int htmlMarkupURLs(FILE *file, char *buf) {
 	static regex_t regex;
-	compile(&regex, "(^|[[:space:]<])(https?:[^[:space:]>]+)(.|$)");
+	compile(&regex, "(^|[[:space:]<])(https?:[^[:space:]>]+)");
 
 	int error;
 	char *ptr;
-	regmatch_t match[4];
-	for (ptr = buf; !regexec(&regex, ptr, 4, match, 0); ptr += match[2].rm_eo) {
+	regmatch_t match[3];
+	for (ptr = buf; !regexec(&regex, ptr, 3, match, 0); ptr += match[2].rm_eo) {
 		char nul = '\0';
 
 		swap(&ptr[match[2].rm_so], &nul);
@@ -242,14 +242,14 @@ static int htmlMarkupURLs(FILE *file, char *buf) {
 		swap(&ptr[match[2].rm_so], &nul);
 
 		const char *template = Q(<a href="[url]">[url]</a>);
-		swap(&ptr[match[3].rm_so], &nul);
+		swap(&ptr[match[2].rm_eo], &nul);
 		struct Variable vars[] = {
 			{ "url", &ptr[match[2].rm_so] },
 			{0},
 		};
 		error = templateRender(file, template, vars, escapeXML);
 		if (error) return error;
-		swap(&ptr[match[3].rm_so], &nul);
+		swap(&ptr[match[2].rm_eo], &nul);
 	}
 	return escapeXML(file, ptr);
 }