Commit Graph
96 Commits
Author SHA1 Message Date
can1357andSylvestre Ledru 98f6b0187b tr: fix test to assert rejection of -ct with complemented class 2026-04-20 23:28:28 +02:00
can1357andSylvestre Ledru 85af4e8159 tr: fix complemented class truncation ordering 2026-04-20 23:28:28 +02:00
AnthonyandGitHub 36ac85b1f3 tests: add WASI integration test support via wasmtime 2026-04-12 15:19:04 +02:00
358063f336 tr: fix graph/print character class mapping (#11405)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-03-26 16:21:28 +01:00
can1357andSylvestre Ledru 7369f4d4fb tr: reject unknown character classes during sequence parsing 2026-03-19 21:57:14 +01:00
David CARLIERandGitHub 99fa1bb9c5 tr: fix possible usage in invalid utf8 set sequence. (#10791) 2026-02-08 11:18:01 +01:00
Johnothan KingandGitHub 6d30b9110a tr: Fix regression causing read error with sockets (#8083)
* tr: Fix regression causing read error with sockets

The test used for determining if a file descriptor
tested with fstat points to a directory is traditionally
done by using the S_IFMT mask[^1][^2], e.g.:
    #define S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
In Rust, this translates to 'm & libc::S_IFMT == libc::S_IFDIR'.
is_stdin_directory() uses 'has!(mode, S_IFDIR)', which is
**not** equivalent and causes non-directory sockets to be
incorrectly recognized as directories. This causes uu-tr
to break when used with all sockets created with socketpair,
including ksh93 pipes[^3]. Below is an example Rust program
demonstrating why the current check is bogus:
  fn main() {
     use nix::sys::socket::{socketpair, SockFlag, AddressFamily, SockType};
     use nix::sys::stat::fstat;
     use libc::{S_IFDIR, S_IFMT, mode_t};
     let (_fd1, fd2) = socketpair(AddressFamily::Unix, SockType::Stream, None, SockFlag::empty()).unwrap();
     let mode = fstat(&fd2).unwrap().st_mode as mode_t;
     if mode & S_IFMT == S_IFDIR {   // Equivalent to S_ISDIR()
         println!("Not reached");    // Not a dir, so unreachable
     }
     if mode & S_IFDIR == S_IFDIR {  // Bogus check for S_IFDIR
         println!("BAD");
     }
  }

- is_stdin_directory(): Fix the regression introduced in 3e4221a4
  by replacing the bogus check with one equivalent to S_ISDIR().
- test_tr.rs: Add a regression test for this bug.

[^1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=io/sys/stat.h;h=4bea9e9a#l123
[^2]: https://git.musl-libc.org/cgit/musl/tree/include/sys/stat.h?id=047a1639#n51
[^3]: https://github.com/ksh93/ksh/blob/cc5e0692/src/cmd/ksh93/sh/io.c#L98-L102

Fixes https://github.com/uutils/coreutils/issues/7658

* Add comment explaining rationale

Also fix cargo clippy lint.
(In case it isn't obvious, I'm fairly new to Rust)

* Fix more lint
2025-07-09 15:47:16 +02:00
yuankunzhang c1eeed61f3 tr: restore default action of SIGPIPE 2025-07-04 22:44:20 +08:00
yuankunzhang 31a5b54dc6 tr: handle broken pipe gracefully 2025-07-02 22:26:11 +08:00
Dorian Peron 6e23d4e979 tests: patch tests to simplify imports 2025-07-01 03:36:46 +02:00
Sylvestre LedruandSylvestre Ledru aba6128fc1 l10n: port tr for translation + add french 2025-06-08 13:57:42 +02:00
Jan Verbeek 181844eafa tr: Flush BufWriter, fix double error context
Write errors led with `tr: tr: write error:`.
2025-03-31 13:46:33 +02:00
Sylvestre Ledru a0179ea239 uutests: adjust the tests to use them 2025-03-28 21:40:31 +01:00
Daniel Hofstetter df4dfea852 tests: replace run() with succeeds() or fails() 2025-03-09 16:53:56 +01:00
Sylvestre Ledru 18cb7dcf9e Use the new function fails_with_code
Done with
```
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs
$ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs
...
```
2025-03-01 17:26:20 +01:00
Dorian PeronandDorian Peron 989b6ba2a0 tr: raise an error when there are two chars or more in an equivalence class 2025-02-19 16:15:40 +01:00
Sylvestre Ledru 3e4221a461 tr: generate an error for real if the input is a directory 2024-12-03 21:38:28 +01:00
Sylvestre LedruandGitHub 2ad3c45230 tr: generate an error if the input is a directory (#6855)
* tr: generate an error if the input is a directory

tested by tests/misc/read-errors

* tr: improve the test

* tr: take the commentinto account
2024-11-30 10:38:46 +01:00
Peng ZijunandGitHub 75de5a0613 tr: Add ambiguous octal escape warning (#6886)
* tr: Add ambiguous octal escape warning, issue #6821

* tr: Make code cleaner
2024-11-28 09:14:16 +01:00
Andrew Liebenow 186d749e94 Replace commented-out code with TODO comments 2024-10-24 13:12:38 -05:00
Andrew Liebenow e53dd5ffe1 tr: forbid non-numeric repeat counts 2024-10-12 03:44:46 -05:00
Andrew Liebenow 0bf5a68c54 tr: forbid backwards ranges 2024-10-12 01:40:05 -05:00
Andrew Liebenow a696e609eb tr: correctly handle multibyte octal sequences 2024-10-12 00:53:54 -05:00
Ben Wiederhake 576374d0c6 tr: enable ignored tests that have already been fixed
Specifically:
- check_against_gnu_tr_tests_e: Yes, the test is about octal interpretation.
- check_against_gnu_tr_tests_ross_0a: Yes, the [Y*] generates multiple Y's, which causes conflicting replacements, which is why the operation is rejected.
- check_against_gnu_tr_tests_ross_0b: Same, plus a newline character was accidentally forgotten.
- check_against_gnu_tr_tests_fowler_1: Apparently the problem was fixed at some point.
2024-10-01 00:57:53 +02:00
Daniel Hofstetter c6f29407b1 tr: enable ignored test on unix 2024-09-25 15:31:03 +02:00