Re: [PATCH v5 1/1] worktree add: sanitize worktree names
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 11, 2019, 06:20 UTC
- Message-ID
- <xmqqbm2ikk4q.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <CAPig+cQYDuKrRwf9GrGZUTnH=BgSyp8Rmh7ON1p+0qOrHxpe3Q@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 13 quoted lines
>> case 2:
>> + if (last == '.') { /* Refname contains "..". */
>> + if (sanitized)
>> + sanitized->len--; /* collapse ".." to single "." */
>
> I think this needs to be:
>
> strbuf_setlen(sanitized, sanitized->len - 1);
>
> to ensure that NUL-terminator ends up in the correct place if this "."
> is the very last character in 'refname'. (Otherwise, the NUL will
> remain after the second ".", thus ".." won't be collapsed to "." at
> all.)True. Why doesn't it do the similar "replace with -" it does for other unfortunate characters, though?