git/t/t7518-ident-corner-cases.sh
brian m. carlson 1c04cb0744 ident: don't consider '.' a crud
When we process a user's name (as in user.name), we strip all
leading and trailing crud from it.  Right now, we consider a dot
a crud character, and strip it off.

However, this is unsuitable for many personal names because humans
frequently have abbreviated suffixes, such as "Jr." or "Sr." at the end
of their names, and this corrupts them.  Some other users may wish to
use an abbreviated name or initial, which will pose a problem especially
in cultures that write the family name first, followed by the personal
name.

Since the current approach causes lots of practical problems, let's
avoid it by no longer considering a dot to be crud.

Note that "." in the name forces the entire name to be quoted to
please mailers, but stripping "." only at the beginning and the end
does not help a name with "." in the middle (like "brian m. carlson")
so this change will not make it much worse.  A name like "Given
Family, Jr." that did not have to be quoted now would need to be, in
order to be placed on the e-mail headers, though.

This is based on a weather-balloon patch by Jeff King sent in Aug 2021
https://lore.kernel.org/git/YSKm8Q8nyTavQaox@coredump.intra.peff.net/

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-08-02 09:50:52 -07:00

59 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
test_description='corner cases in ident strings'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# confirm that we do not segfault _and_ that we do not say "(null)", as
# glibc systems will quietly handle our NULL pointer
#
# Note also that we can't use "env" here because we need to unset a variable,
# and "-u" is not portable.
test_expect_success 'empty name and missing email' '
(
sane_unset GIT_AUTHOR_EMAIL &&
GIT_AUTHOR_NAME= &&
test_must_fail git commit --allow-empty -m foo 2>err &&
test_i18ngrep ! "(null)" err
)
'
test_expect_success 'commit rejects all-crud name' '
test_must_fail env GIT_AUTHOR_NAME=" ,;<>" \
git commit --allow-empty -m foo
'
test_expect_success 'commit does not strip trailing dot' '
author_name="Pat Doe Jr." &&
env GIT_AUTHOR_NAME="$author_name" \
git commit --allow-empty -m foo &&
git log -1 --format=%an >actual &&
echo "$author_name" >expected &&
test_cmp actual expected
'
# We must test the actual error message here, as an unwanted
# auto-detection could fail for other reasons.
test_expect_success 'empty configured name does not auto-detect' '
(
sane_unset GIT_AUTHOR_NAME &&
test_must_fail \
git -c user.name= commit --allow-empty -m foo 2>err &&
test_i18ngrep "empty ident name" err &&
test_i18ngrep "Author identity unknown" err
)
'
test_expect_success 'empty configured name does not auto-detect for committer' '
(
sane_unset GIT_COMMITTER_NAME &&
test_must_fail \
git -c user.name= commit --allow-empty -m foo 2>err &&
test_i18ngrep "empty ident name" err &&
test_i18ngrep "Committer identity unknown" err
)
'
test_done