{"thread":{"id":"6297","subject":"[PATCH] Auto-quote config values in config.c:store_write_pair()","startedAt":"2007-01-09T05:27:41Z","lastAt":"2007-01-09T11:44:08Z","messageCount":4,"participants":["Brian Gernhardt","Junio C Hamano","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"31193","messageId":"20070109052741.GB27927@Hermes.local","threadId":"6297","inReplyTo":null,"subject":"[PATCH] Auto-quote config values in config.c:store_write_pair()","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-01-09T05:27:41Z","receivedAt":"2007-01-09T05:27:41Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"Suggested by Jakub Narebski <jnareb@gmail.com> on the list.\n\nWhen we send a value to store_write_pair(), make sure that the value\nthat gets read out matches the one passed in.  This means that for any\nvalue that contains leading or trailing whitespace or any comment\ncharacter (# and ;), we need to surround it in quotes.\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n config.c               |   14 ++++++++++++++\n t/t1300-repo-config.sh |   17 +++++++++++++++++\n 2 files changed, 31 insertions(+), 0 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 5cbd130..e99681a 100644\n--- a/config.c\n+++ b/config.c\n@@ -496,11 +496,23 @@ static void store_write_section(int fd, const char* key)\n static void store_write_pair(int fd, const char* key, const char* value)\n {\n \tint i;\n+\tint quote = 0;\n+\n+\t/* Check to see if the value needs to be quoted. */\n+\tif (value[0] == ' ')\n+\t\tquote = 1;\n+\tfor (i = 0; value[i]; i++)\n+\t\tif (value[i] == ';' || value[i] == '#')\n+\t\t\tquote = 1;\n+\tif (value[i-1] == ' ')\n+\t\tquote = 1;\n \n \twrite(fd, \"\\t\", 1);\n \twrite(fd, key+store.baselen+1,\n \t\tstrlen(key+store.baselen+1));\n \twrite(fd, \" = \", 3);\n+\tif (quote)\n+\t\twrite(fd, \"\\\"\", 1);\n \tfor (i = 0; value[i]; i++)\n \t\tswitch (value[i]) {\n \t\tcase '\\n': write(fd, \"\\\\n\", 2); break;\n@@ -508,6 +520,8 @@ static void store_write_pair(int fd, const char* key, const char* value)\n \t\tcase '\"': case '\\\\': write(fd, \"\\\\\", 1);\n \t\tdefault: write(fd, value+i, 1);\n \t}\n+\tif (quote)\n+\t\twrite(fd, \"\\\"\", 1);\n \twrite(fd, \"\\n\", 1);\n }\n \ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex a29caa0..60acdd3 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -401,5 +401,22 @@ test_expect_success numbers '\n \ttest z1048576 = \"z$m\"\n '\n \n+rm .git/config\n+\n+git-repo-config quote.leading \" test\"\n+git-repo-config quote.ending \"test \"\n+git-repo-config quote.semicolon \"test;test\"\n+git-repo-config quote.hash \"test#test\"\n+\n+cat > expect << EOF\n+[quote]\n+\tleading = \" test\"\n+\tending = \"test \"\n+\tsemicolon = \"test;test\"\n+\thash = \"test#test\"\n+EOF\n+\n+test_expect_success 'quoting' 'cmp .git/config expect'\n+\n test_done\n \n-- \n1.4.4.4.g4083\n"},{"id":"31202","messageId":"7v7ivwspu8.fsf@assigned-by-dhcp.cox.net","threadId":"6297","inReplyTo":"20070109052741.GB27927@Hermes.local","subject":"Re: [PATCH] Auto-quote config values in config.c:store_write_pair()","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-09T05:59:11Z","receivedAt":"2007-01-09T05:59:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"},{"id":"31223","messageId":"Pine.LNX.4.63.0701091128170.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6297","inReplyTo":"20070109052741.GB27927@Hermes.local","subject":"Re: [PATCH] Auto-quote config values in config.c:store_write_pair()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-01-09T10:29:07Z","receivedAt":"2007-01-09T10:29:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 9 Jan 2007, Brian Gernhardt wrote:\n\n> +\tif (quote)\n> +\t\twrite(fd, \"\\\"\", 1);\n>  \tfor (i = 0; value[i]; i++)\n>  \t\tswitch (value[i]) {\n>  \t\tcase '\\n': write(fd, \"\\\\n\", 2); break;\n> @@ -508,6 +520,8 @@ static void store_write_pair(int fd, const char* key, const char* value)\n>  \t\tcase '\"': case '\\\\': write(fd, \"\\\\\", 1);\n>  \t\tdefault: write(fd, value+i, 1);\n>  \t}\n> +\tif (quote)\n> +\t\twrite(fd, \"\\\"\", 1);\n\nAFAICS this misses the case where you have to quote a single '\"'.\n\nCiao,\nDscho\n"},{"id":"31236","messageId":"Pine.LNX.4.63.0701091242330.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6297","inReplyTo":"7vps9ompix.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Auto-quote config values in config.c:store_write_pair()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-01-09T11:44:08Z","receivedAt":"2007-01-09T11:44:08Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\n[Cc'ing list]\n\nOn Tue, 9 Jan 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > On Tue, 9 Jan 2007, Brian Gernhardt wrote:\n> >\n> >> +\tif (quote)\n> >> +\t\twrite(fd, \"\\\"\", 1);\n> >>  \tfor (i = 0; value[i]; i++)\n> >>  \t\tswitch (value[i]) {\n> >>  \t\tcase '\\n': write(fd, \"\\\\n\", 2); break;\n> >> @@ -508,6 +520,8 @@ static void store_write_pair(int fd, const char* key, const char* value)\n> >>  \t\tcase '\"': case '\\\\': write(fd, \"\\\\\", 1);\n> >>  \t\tdefault: write(fd, value+i, 1);\n> >>  \t}\n> >> +\tif (quote)\n> >> +\t\twrite(fd, \"\\\"\", 1);\n> >\n> > AFAICS this misses the case where you have to quote a single '\"'.\n> \n> \t$ git-repo-config qu.ot 'ab\"cd'\n>         $ git-repo-config --get qu.ot\n>         ab\"cd\n>         $ tail -n 2 .git/config\n>         [qu]\n>         \tot = ab\\\"cd\n\nOooopps! Even more embarassing: you can see it in the diff (it is line 508 \nof the original code). And most embarassing: AFAICT I wrote the code \nmyself!!!\n\nSo I shut up.\n\nCiao,\nDscho\n"}]}