git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 2/5] urlmatch: enable normalization of URLs with globs

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 31, 2017, 09:01 UTC
Message-ID
<dec34b078e3019d7078be6799d3d8c0e28d912ba.1485853153.git.ps@pks.im>
In-Reply-To
<cover.1485853153.git.ps@pks.im>
From: Patrick Steinhardt <patrick.steinhardt@elego.de>

The `url_normalize` function is used to validate and normalize URLs. As such, it does not allow for some special characters to be part of the URLs that are to be normalized. As we want to allow using globs in some configuration keys making use of URLs, namely `http.<url>.<key>`, but still normalize them, we need to somehow enable some additional allowed characters.

To do this without having to change all callers of `url_normalize`, where most do not actually want globbing at all, we split off another function `url_normalize_1`. This function accepts an additional parameter `allow_globs`, which is subsequently called by `url_normalize` with `allow_globs=0`.

As of now, this function is not used with globbing enabled. A caller will be added in the following commit.

Signed-off-by: Patrick Steinhardt <patrick.steinhardt@elego.de>
---
 urlmatch.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/urlmatch.c b/urlmatch.c
index 132d342bc..d350478c0 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -63,7 +63,7 @@ static int append_normalized_escapes(struct strbuf *buf,
 	return 1;
 }
 
-char *url_normalize(const char *url, struct url_info *out_info)
+static char *url_normalize_1(const char *url, struct url_info *out_info, char allow_globs)
 {
 	/*
 	 * Normalize NUL-terminated url using the following rules:
@@ -191,7 +191,12 @@ char *url_normalize(const char *url, struct url_info *out_info)
 		strbuf_release(&norm);
 		return NULL;
 	}
-	spanned = strspn(url, URL_HOST_CHARS);
+
+	if (allow_globs)
+		spanned = strspn(url, URL_HOST_CHARS "*");
+	else
+		spanned = strspn(url, URL_HOST_CHARS);
+
 	if (spanned < colon_ptr - url) {
 		/* Host name has invalid characters */
 		if (out_info) {
@@ -380,6 +385,11 @@ char *url_normalize(const char *url, struct url_info *out_info)
 	return result;
 }
 
+char *url_normalize(const char *url, struct url_info *out_info)
+{
+	return url_normalize_1(url, out_info, 0);
+}
+
 static size_t url_match_prefix(const char *url,
 			       const char *url_prefix,
 			       size_t url_prefix_len)
-- 
2.11.0
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 of 6 in “urlmatch: allow wildcard-based matches”
  1. 0/5 urlmatch: allow wildcard-based matchesPatrick Steinhardt, Jan 31, 2017
  2. 5/5 urlmatch: allow globbing for the URL host partPatrick Steinhardt, Jan 31, 2017
  3. 2/5 urlmatch: enable normalization of URLs with globsPatrick Steinhardt, Jan 31, 2017
  4. 1/5 mailmap: add Patrick Steinhardt's work addressPatrick Steinhardt, Jan 31, 2017
  5. 3/5 urlmatch: split host and port fields in `struct url_info`Patrick Steinhardt, Jan 31, 2017
  6. 4/5 urlmatch: include host in urlmatch rankingPatrick Steinhardt, Jan 31, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.