Re: [PATCH] Extend sample pre-commit hook to check for non ascii filenames

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

 



Heiko Voigt schrieb:
> +# is_ascii() Tests the string given given on standard input for
> +# printable ascii conformance. We exploit the fact that the printable
> +# range starts at the space character and ends with tilde.
> +is_ascii() {
> +    test -z "$(LC_ALL=C tr -d \ -~)"
> +}
> +
> +if [ "$allownonascii" != "true" ]
> +then
> +	# until git can handle non-ascii filenames gracefully
> +	# prevent them to be added into the repository
> +	if ! git diff --cached --name-only --diff-filter=A -z \
> +	   | tr "\0" "\n" | is_ascii; then

Will this not fail to add more than one file with allowed names? The \n is
not removed in is_ascii(), and so the resulting string will not be empty.

BTW, not all tr work well with NULs. See the commit message of e85fe4d8,
for example. Otherwise, I would have suggested to convert the NUL to some
allowed ASCII character, e.g. 'A'. BTW, you should really use '\0' and
'\n' (single-quotes) to guarantee that the shell does not ignore the
backslash.

-- Hannes

--
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]