[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] md5sum, sha*sum: only escape file names containing newlines
From: |
Pádraig Brady |
Subject: |
Re: [PATCH] md5sum, sha*sum: only escape file names containing newlines |
Date: |
Fri, 01 Nov 2013 17:03:24 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 11/01/2013 04:44 PM, Jim Meyering wrote:
> On Fri, Nov 1, 2013 at 9:29 AM, Pádraig Brady <address@hidden> wrote:
>> This should be fully backwards and forwards compatible with previous
>> escaping, since we'll never have a file name at the start of a line,
>> thus '\' at the start of a line always means the file name is escaped.
>>
>> * src/md5sum.c (main): Only escape the output (with a leading '\')
>> when a '\n' character is present in the file name. There is no
>> need to do this in the more likely case where a '\' character is
>> present in the name. Note this is faster also as we only scan the
>> file name once (for '\n') rather than four times.
>> (print_filename): Use the predetermined boolean as to whether to
>> escape or not, so that in the common case we can output the
>> file name directly, rather than inspecting each character.
>> * tests/misc/md5sum.pl: Adjust accordingly.
>> * tests/misc/sha1sum.pl: Likewise.
>
> Good idea. Thanks! I had to read through it twice to realize that
> when escaping is done, backslash is still escaped. It's just
> that the trigger is now the presence of newline, not backslash.
>
> If you say something like the following, it might be easier to understand:
>
> Escape the output (marking with a leading '\' and backslash-escaping
> both '\' and '\n') only when the file name contains a newline.
> Before, we would do that for a file name containing either newline or
> backslash.
>
> This probably deserves a NEWS entry, since it is user-visible.
I debated that as I thought it could have no impact on anything,
but it could actually if one was comparing old and new outputs?
newsum=$(md5sum my file set | md5sum)
[ "$newsum" = "$(cat ./oldsum)" ] || error
Given the above is a bit contrived,
and also this is in the unlikely case
of file names containing '\' it's probably
still OK to apply with a NEWS entry.
thanks,
Pádraig.
Re: [PATCH] md5sum, sha*sum: only escape file names containing newlines, Eric Blake, 2013/11/01