# [PATCH] remote-curl: Add sanity check for url

3 messages from 2010-03-30 to 2010-03-31. Participants: Ramkumar Ramachandra, Junio C Hamano.
Thread: https://gitlist.dev/t/23259

## Ramkumar Ramachandra, 2010-03-30 20:08

Subject: [PATCH] remote-curl: Add sanity check for url
Message-ID: <f3271551003301308y683173f6y6a4fadb01b791049@mail.gmail.com>
URL: https://gitlist.dev/e/f3271551003301308y683173f6y6a4fadb01b791049%40mail.gmail.com

```
Previously, `git remote-http foo` and subsquent commands would try to
work on a HTML page. This patch fixes the bug by making one assumption
about the URL handled by libcurl: it must contain the string "://"

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 remote-curl.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/remote-curl.c b/remote-curl.c
index b76bfcb..9320897 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -112,6 +112,9 @@ static struct discovery* discover_refs(const char *service)
 	}
 	refs_url = strbuf_detach(&buffer, NULL);

+	/* sanity check: does this look like a url expected by libcurl? */
+	if (!strstr(url, "://"))
+		die("%s is not a url supported by this remote helper", url);
 	http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);

 	/* try again with "plain" url (no ? or & appended) */
-- 
1.7.0.3

```

## Junio C Hamano, 2010-03-30 23:45

Subject: Re: [PATCH] remote-curl: Add sanity check for url
Message-ID: <7voci5qspr.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7voci5qspr.fsf%40alter.siamese.dyndns.org
In-Reply-To: <f3271551003301308y683173f6y6a4fadb01b791049@mail.gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Previously, `git remote-http foo` and subsquent commands would try to
> work on a HTML page. This patch fixes the bug by making one assumption
> about the URL handled by libcurl: it must contain the string "://"

I may be being slow but I do not see the point of this patch.

I thought that remote-foo is never invoked directly from a command line
with random arguments, and fetch/push frontends make the decision based on
the shape of the "URL" (or whatever data used to reach the remote end)
which helper to run.

I do not think your patch would _break_ anything, but my question is more
about the reason why we would want a duplicated check here.

```

## Ramkumar Ramachandra, 2010-03-31 02:43

Subject: Re: [PATCH] remote-curl: Add sanity check for url
Message-ID: <u2tf3271551003301943sf703e66fz4274135efd991430@mail.gmail.com>
URL: https://gitlist.dev/e/u2tf3271551003301943sf703e66fz4274135efd991430%40mail.gmail.com
In-Reply-To: <7voci5qspr.fsf@alter.siamese.dyndns.org>

```
Hi,

> I may be being slow but I do not see the point of this patch.

Agreed, it's not a bug that any end-user would normally bump into. I
bumped into this myself when I assumed that the remote `foo` exists,
and invoked `git-remote-http foo`. Since remote_get() transparently
creates a remote when one does not exist, remote-curl doesn't know if
the remote `foo` ever really exists. Going off to fetch a HTML page
when an expected remote doesn't exist is really ugly, so I thought I'd
prepare this patch. Plus, it doesn't hurt to make sure that the remote
helper conforms to the documentation- useful when a developer is
calling it independently.

-- Ram

```
