Hi,

I mentioned this a few times in passing on other lists, but forgot to
bring it up here.

POSIX.1-2024 added the following change to many programs, using 'touch'
as an example [1]:

    Austin Group Defect 251 is applied, encouraging implementations to
    disallow the creation of filenames containing any bytes that have
    the encoded value of a <newline> character.

With the FUTURE DIRECTIONS having the following text:

    If this utility is directed to create a new directory entry that
    contains any bytes that have the encoded value of a <newline>
    character, implementations are encouraged to treat this as an error.
    A future version of this standard may require implementations to
    treat this as an error.

The goal seems to have been to avoid bugs like this example [2]:

    $ for file in `find . -type f`; do if ! test -f "$file"; \
        then echo "$file"; fi; done
    ./file
    2

Here is a safe way to write that:

    $ find . -type f -print0 | while IFS= read -r -d '' file; \
        do if ! test -f "$file"; then echo "$file"; fi; done

My personal opinion is that that we shouldn't restrict a user from
creating a file with a name that their operating system and file system
support.

If a future POSIX release requires us to throw an error if a file name
has newline, I would propose only enforcing it if POSIXLY_CORRECT is
set. Probably with a function in Gnulib so that diffutils, patch, etc.
can use it.

Thoughts?

Collin

[1] https://pubs.opengroup.org/onlinepubs/9799919799/utilities/touch.html
[2] https://www.austingroupbugs.net/view.php?id=251

Reply via email to