Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls: Fix quoting for dirnames with a colon : in recursive mode, and patch the quote-align GNU test #6559

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

RenjiSann
Copy link
Contributor

Fixes #6554 and adds a test for it.

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@RenjiSann
Copy link
Contributor Author

@BenWiederhake @sylvestre @tertsdiepraam ping, if one of you has the time to take a look :)

@sylvestre
Copy link
Sponsor Contributor

Sorry, i didn't look because your test fails a bunch of jobs:

--- TRY 3 STDERR:        coreutils::tests test_ls::test_ls_recursive_escape_dirname ---
thread 'test_ls::test_ls_recursive_escape_dirname' panicked at tests\common\util.rs:956:40:
called `Result::unwrap()` on an `Err` value: Os { code: 267, kind: NotADirectory, message: "The directory name is invalid." }
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\std\src\panicking.rs:652
   1: core::panicking::panic_fmt
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\core\src\panicking.rs:72
   2: core::result::unwrap_failed
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\core\src\result.rs:1654
   3: enum2$<core::result::Result<tuple$<>,std::io::error::Error> >::unwrap
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081\library\core\src\result.rs:1077
   4: tests::common::util::AtPath::mkdir<ref$<str$> >
             at .\tests\common\util.rs:956
   5: tests::test_ls::test_ls_recursive_escape_dirname
             at .\tests\by-util\test_ls.rs:2204
   6: tests::test_ls::test_ls_recursive_escape_dirname::closure$0
             at .\tests\by-util\test_ls.rs:2201
   7: core::ops::function::FnOnce::call_once<tests::test_ls::test_ls_recursive_escape_dirname::closure_env$0,tuple$<> >
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081\library\core\src\ops\function.rs:250
   8: core::ops::function::FnOnce::call_once
             at /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

src/uu/ls/src/ls.rs Outdated Show resolved Hide resolved
@RenjiSann RenjiSann force-pushed the renji/fix-6554 branch 5 times, most recently from ff73f42 to a754178 Compare July 22, 2024 08:34
@RenjiSann
Copy link
Contributor Author

RenjiSann commented Jul 22, 2024

I have guessed that when using the shell quoting style, with show-control-chars display enabled, ls should quote the name if it does encounter a control character.

Commit 83c1447 handle this case.

EDIT: It seems that in shell mode, control characters induce simple quoting, no matter the status of show_control.

@RenjiSann RenjiSann force-pushed the renji/fix-6554 branch 3 times, most recently from 9c5b073 to c709722 Compare July 22, 2024 14:18
@RenjiSann
Copy link
Contributor Author

I have made a substantial change in the quoting_style file, regarding the quoting behavior of control characters in shell-* modes.

Even though I am pretty sure this change is sound for ls, it might have repercussions on other utils that use quoting_style

@RenjiSann
Copy link
Contributor Author

I realize this PR does duplicate the work in #6555.

Let's compare the changes and keep the best of both.

@RenjiSann RenjiSann changed the title ls: Fix quoting for dirnames with a colon : in recursive mode ls: Fix quoting for dirnames with a colon : in recursive mode, and patch the quote-align GNU test Jul 25, 2024
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/ls/quote-align is no longer failing!
Congrats! The gnu test tests/rm/rm2 is no longer failing!

@RenjiSann
Copy link
Contributor Author

Style/Lint jobs are failing due to the clippy bump, but I will rebase the PR once #6592 has landed.

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/ls/quote-align is no longer failing!
Congrats! The gnu test tests/rm/rm2 is no longer failing!

@RenjiSann
Copy link
Contributor Author

I keep finding edge cases : \a is a control character, yet it shall not be escaped in shell mode. I need to rework my solution.

So far:

$ LC_ALL=C /usr/bin/ls --quoting=shell test
 xx?bell   xx?backspace  'xx?tab'  'xx?linefeed'   xx?vtab   xx?formfeed  'xx?carriage'  'xx space'

$ LC_ALL=C ./target/debug/ls --quoting=shell test
'xx?bell'  'xx?backspace'  'xx?tab'  'xx?linefeed'  'xx?vtab'  'xx?formfeed'  'xx?carriage'  'xx space'

I don't see a specific pattern, so I guess we will have to do it by hand.

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/quote-align is no longer failing!

@RenjiSann
Copy link
Contributor Author

@sylvestre @cakebaker @tertsdiepraam ping (also, is there one of you I should ping in priority for this ?)

@RenjiSann
Copy link
Contributor Author

@BenWiederhake Just remembered I can notify you as well

@BenWiederhake
Copy link
Collaborator

While this does improve the situation significantly, there are still a few closely-related special characters that are handled incorrectly. I would strongly prefer that we fix all ASCII characters in one fell swoop. Can you add tests and handling for these, too?

Specifically:

  • --quoting-style=shell: each of the four characters in ]^{} should not be escaped (but we do), = should be escaped (but we don't)
  • Note in particular that [ should YES be escaped, and we handle this correctly. Wild.
  • Same with --quoting-style=shell

@RenjiSann
Copy link
Contributor Author

RenjiSann commented Aug 12, 2024

Same with --quoting-style=shell

Did you mean --quoting-style=shell-escape ?

@RenjiSann
Copy link
Contributor Author

Also, I think you inverted for ^ : with --quoting-style=shell, a caret should be escaped, and we currently don't

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/quote-align is no longer failing!

Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/ls/quote-align is no longer failing!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/quote-align is no longer failing!

Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/ls/quote-align is no longer failing!
Skipping an intermittent issue tests/rm/rm1 (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/timeout/timeout is no longer failing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ls: gnu test case quote-align compatibility
4 participants