Re: [PATCH] Quote LF in urls git fetch saves in FETCH_HEAD

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Strip trailing spaces off guessed target directory, and replace every
'control' character in the new directory name with ASCII space (\x20).

The user still can have any name by specifying it explicitely after url.

Signed-off-by: Alex Riesen <raa.lkml@xxxxxxxxx>
---

Alex Riesen, Wed, May 13, 2009 18:09:42 +0200:
> 2009/5/13 Daniel Barkalow <barkalow@xxxxxxxxxxxx>:
> > On Wed, 13 May 2009, Alex Riesen wrote:
> >> 2009/5/13 Junio C Hamano <gitster@xxxxxxxxx>:
> >>
> >> > If it is just informational use only, then it might make more sense to
> >> > drop this ugly "quoted \n" silently.  I dunno.
> >>
> >> That'd mean to loose the information completely. Which is just as bad
> >> as putting the LF in the url in the first place.
> >
> > Looking back at the original message, it looks like the user included a
> > newline in an argument to clone, and the fetch must have stripped it out
> > (or ignored it in some other fashion), because data was retrieved from a
> > repository that doesn't have a newline in its name.
> 
> _That_ looks like a bug to me. We should have asked exactly the name
> we were given, or notify the user about what we have used for the url
> if we have ignored user's input and decided to use something else.
> Patches follow.
> 

Now I just have to figure out why the fetch works. Something seem to
strip spaces off urls...

 builtin-clone.c |   24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/builtin-clone.c b/builtin-clone.c
index 880373f..bdbe931 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -104,11 +104,12 @@ static char *get_repo_path(const char *repo, int *is_bundle)
 static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
 {
 	const char *end = repo + strlen(repo), *start;
+	char *dir;
 
 	/*
-	 * Strip trailing slashes and /.git
+	 * Strip trailing spaces, slashes and /.git
 	 */
-	while (repo < end && is_dir_sep(end[-1]))
+	while (repo < end && (is_dir_sep(end[-1]) || isspace(end[-1])))
 		end--;
 	if (end - repo > 5 && is_dir_sep(end[-5]) &&
 	    !strncmp(end - 4, ".git", 4)) {
@@ -140,10 +141,21 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
 	if (is_bare) {
 		struct strbuf result = STRBUF_INIT;
 		strbuf_addf(&result, "%.*s.git", (int)(end - start), start);
-		return strbuf_detach(&result, 0);
-	}
-
-	return xstrndup(start, end - start);
+		dir = strbuf_detach(&result, 0);
+	} else
+		dir = xstrndup(start, end - start);
+	/* replace all 'control' characters with ascii space */
+	for (start = dir; *start; ++start)
+		if (*(const unsigned char *)start < 32u)
+			dir[start - dir] = '\x20';
+	/* remove trailing spaces */
+	if (dir < start)
+		for (end = start; dir < --end; )
+			if (!isspace(*end))
+				break;
+			else
+				dir[end - dir] = '\0';
+	return dir;
 }
 
 static void strip_trailing_slashes(char *dir)
-- 
1.6.3.28.ga852b

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]