Commit Graph
74 Commits
Author SHA1 Message Date
Sylvestre LedruandGitHub a9136fb863 printf: fix %q shell quoting with control chars and quotes (#10816) 2026-02-08 14:10:09 -05:00
oech3andoech3 dc433bcacb printf 1 > /dev/full is not silent 2026-01-11 14:05:04 +09:00
Sylvestre Ledru 0b63ffca5c printf: Format String Parsing Overflow Causes Panic
Closes: https://github.com/uutils/coreutils/issues/9697
2025-12-18 18:30:21 +01:00
Sylvestre Ledru c8663b9112 printf: handle extremely large format widths gracefully to fix GNU test panic 2025-11-03 23:32:37 +01:00
Sylvestre Ledru 3ed1f47de3 add more emoji tests 2025-09-03 22:39:21 +02:00
961a27acff printf: accept non-UTF-8 input in FORMAT and ARGUMENT arguments
Other implementations of `printf` permit arbitrary data to be passed
to `printf`. The only restriction is that a null byte terminates
FORMAT and ARGUMENT argument strings (since they are C strings).

The current implementation only accepts FORMAT and ARGUMENT
arguments that are valid UTF-8 (this is being enforced by clap).

This commit removes the UTF-8 validation by switching to OsStr
and OsString.

This allows users to use `printf` to transmit or reformat null-safe
but not UTF-8-safe data, such as text encoded in an 8-bit text
encoding. See the `non_utf_8_input` test for an example (ISO-8859-1
text).

[drinkcat: also squashed in this commit to ease rebase]
Author: Justin Tracey <jdt.dev@unsuspicious.click>

uucore, printf: improve non-UTF-8 format arguments

This fixes handling of format arguments, in part by eliminating duplicate
implementations. Utilities with format arguments other than printf will no
longer accept things like "'a" as numbers, etc.

Co-authored-by: Justin Tracey <jdt.dev@unsuspicious.click>
2025-07-16 00:28:34 +02:00
Yuri AstrakhanandDaniel Hofstetter 206281e29b chore: fix uninlined_format_args lint
I used this command, plus some manual fixes:

```sh
__CARGO_FIX_YOLO=1 cargo clippy --fix --all-targets --workspace --all-features --allow-dirty
```
2025-07-09 10:50:36 +02:00
Dorian Peron 6e23d4e979 tests: patch tests to simplify imports 2025-07-01 03:36:46 +02:00
Teemu Pätsi cf7255f085 printf: Test formatting hex with padding 2025-06-15 00:36:38 +03:00
Justin Tracey 27487be267 printf: use non-zero indexes 2025-04-28 14:06:12 -04:00
Joseph Jon Booker 7f98d98472 printf: Add indexing to format strings 2025-04-24 22:11:49 -05:00
Sylvestre LedruandJustin Tracey af577e7a14 printf: support for extract chars
Should fix tests/printf/printf-mb.sh
2025-04-18 00:39:13 -04:00
Sylvestre LedruandJustin Tracey e5980d4d2a printf: simplify and dedup some tests 2025-04-18 00:38:57 -04:00
Sylvestre LedruandJustin Tracey 8ff0db1db9 printf: Improve support for printing multi-byte values of characters 2025-04-18 00:38:48 -04:00
Nicolas Boichat fce9f79618 tests: printf: Add more cases around 0, missing digits, etc. 2025-04-15 20:59:35 +02:00
Joseph Jon Booker 9f1e7a2075 printf: Add integration test for %q '' 2025-04-12 21:44:06 -05:00
Joseph Jon Booker 7df22051ea printf: Ignore thousand seperator flag 2025-04-11 23:17:50 -05:00
Joseph Jon Booker ef7a8c300e printf: add error handling to escaped unicode characters 2025-04-11 23:17:50 -05:00
Sylvestre LedruandGitHub a89fc48388 Merge pull request #7656 from eduardorittner/main
printf: make negative values wrap around with unsigned/hex format
2025-04-10 06:48:50 -04:00
eduardorittner 36ef5010e3 printf: make negative values wrap around with unsigned/hex format
To convert from negative to unsigned with overflow, we get the two's complement
representation of the absolute (unsigned) value.
2025-04-06 18:58:56 -03:00
Joseph Jon Booker 6061b67601 printf: add tests for different octal lengths 2025-04-05 02:02:33 -05:00
Joseph Jon Booker 95e5396c4c printf: Consistently handle negative widths/precision
Also allows character constants with " instead of ', and for
interpolated values with %b to use \0XXX notation for octal bytes
2025-04-05 02:02:31 -05:00
Nicolas Boichat 8cf4da0b19 uucore: format: Fix hexadecimal default format print
The default hex format, on x86(-64) prints 15 digits after the
decimal point, _but_ also trims trailing zeros, so it's not just
a simple default precision and a little bit of extra handling is
required.

Also add a bunch of tests.

Fixes #7364.
2025-04-01 15:04:47 +02:00
Nicolas Boichat 1e104b7ef9 uucore: format: num_parser: Add value to Overflow error
When parsing integers, we should still return the min/max value
of the type (depending on the type), and wrap that in the error.

We need to refactor the map function to handle this case better,
and add an extract function to get the value out of an error
(if any).

This fixes the integer part of #7508.
2025-04-01 11:20:17 +02:00
Nicolas Boichat b5a658528b uucore: format: Use ExtendedBigDecimal in argument code
Provides arbitrary precision for float parsing in printf.

Also add a printf test for that.
2025-03-31 10:04:08 +02:00