Skip to content

Handle non-UTF-8 in quoting style #6817

Closed
@RenjiSann

Description

@RenjiSann

Right now, quoting-style uses String::from_utf8_lossy to handle the quoting of given inputs, which replaces the non UTF-8 characters with the replacement character \u{FFFD}.

It may a problem for several utils:

ls

$ touch "`echo -ne 'funky\xffname'`"
$ ls
'funky'$'\377''name'

$ ../../target/debug/ls
funky�name

cksum and hashsum checking

Here, quoting is used to print in stderr when a file is a directory or not found

$ echo -ne `SHA256` (XXX\xffXXX) = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' > CHECKSUM

$ cksum -c CHECKSUM
cksum: 'XXX'$'\377''XXX': No such file or directory
XXXXXX: FAILED open or read
cksum: WARNING: 1 listed file could not be read

$ ../../target/debug/cksum -c CHECKSUM 
../../target/debug/cksum: XXX�XXX: No such file or directory # Here, the file should be escaped
XXXXXX: FAILED open or read
../../target/debug/cksum: WARNING: 1 listed file could not be read

There are probably some other places where correctly quoting non UTF-8 characters might prove useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions