{"thread":{"id":"28743","subject":"[PATCH] make the sample pre-commit hook script reject names with newlines, too","startedAt":"2011-10-22T17:19:07Z","lastAt":"2011-10-22T17:44:40Z","messageCount":3,"participants":["Jim Meyering","Andreas Schwab"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"178163","messageId":"87obx9eygk.fsf@rho.meyering.net","threadId":"28743","inReplyTo":null,"subject":"[PATCH] make the sample pre-commit hook script reject names with newlines, too","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2011-10-22T17:19:07Z","receivedAt":"2011-10-22T17:19:07Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"\nThe sample pre-commit hook script would fail to reject a file name\nlike \"a\\nb\" because of the way newlines are handled in \"$(...)\".\nAdjust the test to count filtered bytes and require there be 0.\nAlso print all diagnostics to standard error, not stdout, so they\nwill actually be seen.\n\nSigned-off-by: Jim Meyering <meyering@redhat.com>\n---\n templates/hooks--pre-commit.sample |    6 +++++-\n 1 files changed, 5 insertions(+), 1 deletions(-)\n\ndiff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\nindex b187c4b..1addec5 100755\n--- a/templates/hooks--pre-commit.sample\n+++ b/templates/hooks--pre-commit.sample\n@@ -18,6 +18,9 @@ fi\n # If you want to allow non-ascii filenames set this variable to true.\n allownonascii=$(git config hooks.allownonascii)\n\n+# Redirect output to stderr.\n+exec 1>&2\n+\n # Cross platform projects tend to avoid non-ascii filenames; prevent\n # them from being added to the repository. We exploit the fact that the\n # printable range starts at the space character and ends with tilde.\n@@ -26,7 +29,7 @@ if [ \"$allownonascii\" != \"true\" ] &&\n \t# even required, for portability to Solaris 10's /usr/bin/tr), since\n \t# the square bracket bytes happen to fall in the designated range.\n \ttest \"$(git diff --cached --name-only --diff-filter=A -z $against |\n-\t  LC_ALL=C tr -d '[ -~]\\0')\"\n+\t  LC_ALL=C tr -d '[ -~]\\0' | wc -c)\" != 0\n then\n \techo \"Error: Attempt to add a non-ascii file name.\"\n \techo\n@@ -43,4 +46,5 @@ then\n \texit 1\n fi\n\n+# If there are whitespace errors, print the offending file names and fail.\n exec git diff-index --check --cached $against --\n--\n1.7.7.419.g87009\n"},{"id":"178167","messageId":"m262jhoro1.fsf@igel.home","threadId":"28743","inReplyTo":"87obx9eygk.fsf@rho.meyering.net","subject":"Re: [PATCH] make the sample pre-commit hook script reject names with newlines, too","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2011-10-22T17:35:42Z","receivedAt":"2011-10-22T17:35:42Z","isPatch":true,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Jim Meyering <jim@meyering.net> writes:\n\n> @@ -26,7 +29,7 @@ if [ \"$allownonascii\" != \"true\" ] &&\n>  \t# even required, for portability to Solaris 10's /usr/bin/tr), since\n>  \t# the square bracket bytes happen to fall in the designated range.\n>  \ttest \"$(git diff --cached --name-only --diff-filter=A -z $against |\n> -\t  LC_ALL=C tr -d '[ -~]\\0')\"\n> +\t  LC_ALL=C tr -d '[ -~]\\0' | wc -c)\" != 0\n\nThis will fail if the output of wc contains leading spaces.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"178168","messageId":"87aa8sgbuf.fsf@rho.meyering.net","threadId":"28743","inReplyTo":"m262jhoro1.fsf@igel.home","subject":"Re: [PATCH] make the sample pre-commit hook script reject names with newlines, too","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2011-10-22T17:44:40Z","receivedAt":"2011-10-22T17:44:40Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Andreas Schwab wrote:\n> Jim Meyering <jim@meyering.net> writes:\n>\n>> @@ -26,7 +29,7 @@ if [ \"$allownonascii\" != \"true\" ] &&\n>>  \t# even required, for portability to Solaris 10's /usr/bin/tr), since\n>>  \t# the square bracket bytes happen to fall in the designated range.\n>>  \ttest \"$(git diff --cached --name-only --diff-filter=A -z $against |\n>> -\t  LC_ALL=C tr -d '[ -~]\\0')\"\n>> +\t  LC_ALL=C tr -d '[ -~]\\0' | wc -c)\" != 0\n>\n> This will fail if the output of wc contains leading spaces.\n\nGood point.  Thanks.  That's a portability bug.\nGNU wc outputs no leading spaces, but others certainly do.\n\nRemoving the double quotes fixes that:\n\n-- >8 --\nSubject: [PATCH] make the sample pre-commit hook script reject names with\n newlines, too\n\nThe sample pre-commit hook script would fail to reject a file name\nlike \"a\\nb\" because of the way newlines are handled in \"$(...)\".\nAdjust the test to count filtered bytes and require there be 0.\nAlso print all diagnostics to standard error, not stdout, so they\nwill actually be seen.\n\nSigned-off-by: Jim Meyering <meyering@redhat.com>\n---\n templates/hooks--pre-commit.sample |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample\nindex b187c4b..18c4829 100755\n--- a/templates/hooks--pre-commit.sample\n+++ b/templates/hooks--pre-commit.sample\n@@ -18,6 +18,9 @@ fi\n # If you want to allow non-ascii filenames set this variable to true.\n allownonascii=$(git config hooks.allownonascii)\n\n+# Redirect output to stderr.\n+exec 1>&2\n+\n # Cross platform projects tend to avoid non-ascii filenames; prevent\n # them from being added to the repository. We exploit the fact that the\n # printable range starts at the space character and ends with tilde.\n@@ -25,8 +28,8 @@ if [ \"$allownonascii\" != \"true\" ] &&\n \t# Note that the use of brackets around a tr range is ok here, (it's\n \t# even required, for portability to Solaris 10's /usr/bin/tr), since\n \t# the square bracket bytes happen to fall in the designated range.\n-\ttest \"$(git diff --cached --name-only --diff-filter=A -z $against |\n-\t  LC_ALL=C tr -d '[ -~]\\0')\"\n+\ttest $(git diff --cached --name-only --diff-filter=A -z $against |\n+\t  LC_ALL=C tr -d '[ -~]\\0' | wc -c) != 0\n then\n \techo \"Error: Attempt to add a non-ascii file name.\"\n \techo\n@@ -43,4 +46,5 @@ then\n \texit 1\n fi\n\n+# If there are whitespace errors, print the offending file names and fail.\n exec git diff-index --check --cached $against --\n--\n1.7.7.419.g87009\n"}]}