Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Gernhardt <benji@silverinsanity.com>2007-01-09 08:27:41 +0300
committerJunio C Hamano <junkio@cox.net>2007-01-09 09:00:18 +0300
commitcdd4fb15cf06ec1de588bee4576509857d8e2cb4 (patch)
tree83341bf9b9b28007f2d92a344b0c1cb7df0e54c2 /config.c
parentbaee1e91ed41cd369ca3ddd63615b64feaa0286f (diff)
Auto-quote config values in config.c:store_write_pair()
Suggested by Jakub Narebski <jnareb@gmail.com> on the list. When we send a value to store_write_pair(), make sure that the value that gets read out matches the one passed in. This means that for any value that contains leading or trailing whitespace or any comment character (# and ;), we need to surround it in quotes. Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'config.c')
-rw-r--r--config.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/config.c b/config.c
index 9ded954496..2cd0263e13 100644
--- a/config.c
+++ b/config.c
@@ -513,11 +513,23 @@ static int store_write_pair(int fd, const char* key, const char* value)
{
int i;
int length = strlen(key+store.baselen+1);
+ int quote = 0;
+
+ /* Check to see if the value needs to be quoted. */
+ if (value[0] == ' ')
+ quote = 1;
+ for (i = 0; value[i]; i++)
+ if (value[i] == ';' || value[i] == '#')
+ quote = 1;
+ if (value[i-1] == ' ')
+ quote = 1;
if (write_in_full(fd, "\t", 1) != 1 ||
write_in_full(fd, key+store.baselen+1, length) != length ||
write_in_full(fd, " = ", 3) != 3)
return 0;
+ if (quote && write_in_full(fd, "\"", 1) != 1)
+ return 0;
for (i = 0; value[i]; i++)
switch (value[i]) {
case '\n':
@@ -537,6 +549,8 @@ static int store_write_pair(int fd, const char* key, const char* value)
return 0;
break;
}
+ if (quote && write_in_full(fd, "\"", 1) != 1)
+ return 0;
if (write_in_full(fd, "\n", 1) != 1)
return 0;
return 1;