Repository navigation
find: escape unusual characters in -ls and -fls file names - #1072
Open
andretorresdg wants to merge 1 commit into
Open
andretorresdg wants to merge 1 commit into
andretorresdg wants to merge 1 commit into
Conversation
GNU find escapes the file name and symlink target in -ls/-fls output: white space, backslash and double quote get a C-style escape (\ , \t, \n, \\, \", ...), and other bytes outside printable ASCII are written as three-digit octal escapes. We printed the name as is, through to_string_lossy, so a name with a newline split the listing over two lines and invalid UTF-8 bytes turned into U+FFFD. Build the line as bytes and escape the name and link target the same way on Unix.
Merging this PR will not alter performance1 warning
Comparing |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1072 +/- ##
==========================================
+ Coverage 92.44% 92.48% +0.04%
==========================================
Files 38 38
Lines 8894 8920 +26
Branches 440 440
==========================================
+ Hits 8222 8250 +28
+ Misses 532 531 -1
+ Partials 140 139 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GNU find escapes the file name (and the symlink target) in
-ls/-flsoutput, as described under "UNUSUAL FILENAMES" in find(1): white space, backslash and double quote get a C-style escape (\,\t,\n,\\,\", ...), any other byte outside printable ASCII is written as a three-digit octal escape, and the rest is copied as is.We printed the name unchanged through
to_string_lossy, so a name containing a newline split one entry over two lines and invalid UTF-8 bytes became U+FFFD:The line is now built as bytes on Unix and the name and link target go through a small escaping helper. The non-Unix branch is left as is (escaping
\there would double every Windows path separator).This is the same fix #935 attempted (closed by its author because it was written with GNU's source in view). This one is written only from find(1) and by comparing output with GNU find 4.11; it also adds the unit test for the escaping helper suggested in that review, covering
\b,\r,\fand 0x7f.Closes #1062
How I tested
push_escaped_name_escapes_unusual_bytesunit test inls.rscovering every branch of the helper.find_ls_escapes_unusual_characterstest intests/test_find.rs(fails before, passes after), covering-lsand-fls, control characters,"/\, invalid UTF-8, a non-ASCII UTF-8 name and a symlink target.-lsoutput with GNU find 4.11.0 for files named with every byte 0x01-0xff (except/): identical.cargo test,cargo fmt --all -- --check,cargo clippy --all-targets -- -D warnings.