From 4dd23b96d1f394d3061290c91eb5cd9ec7ef9988 Mon Sep 17 00:00:00 2001 From: Socialpranker <273312799+Socialpranker@users.noreply.github.com> Date: Sat, 5 Sep 2026 21:50:44 +0200 Subject: [PATCH] base32, base64, basenc: drop the "error: " from the invalid-input message The diagnostic already carries the program name, so the extra literal made it read "base64: error: invalid input" where GNU writes "base64: invalid input". --- src/uu/base32/locales/en-US.ftl | 1 + src/uu/base32/locales/fr-FR.ftl | 1 + src/uu/base32/src/base_common.rs | 21 ++++++++++++--- src/uucore/locales/en-US.ftl | 4 +++ src/uucore/locales/fr-FR.ftl | 4 +++ src/uucore/src/lib/features/encoding.rs | 35 ++++++++++++++++--------- tests/by-util/test_base32.rs | 2 +- tests/by-util/test_base64.rs | 2 +- tests/by-util/test_basenc.rs | 10 +++---- util/build-gnu.sh | 3 --- 10 files changed, 56 insertions(+), 27 deletions(-) diff --git a/src/uu/base32/locales/en-US.ftl b/src/uu/base32/locales/en-US.ftl index 925e5c70a25..cbe8135cbba 100644 --- a/src/uu/base32/locales/en-US.ftl +++ b/src/uu/base32/locales/en-US.ftl @@ -52,6 +52,7 @@ base-common-extra-operand = extra operand {$operand} base-common-no-such-file = {$file}: No such file or directory base-common-invalid-wrap-size = invalid wrap size: {$size} base-common-read-error = read error: {$error} +base-common-invalid-input = invalid input # Shared base_common help messages base-common-help-decode = decode data diff --git a/src/uu/base32/locales/fr-FR.ftl b/src/uu/base32/locales/fr-FR.ftl index c5ca10b7109..2cff6648d05 100644 --- a/src/uu/base32/locales/fr-FR.ftl +++ b/src/uu/base32/locales/fr-FR.ftl @@ -47,6 +47,7 @@ base-common-extra-operand = opérande supplémentaire {$operand} base-common-no-such-file = {$file} : Aucun fichier ou répertoire de ce type base-common-invalid-wrap-size = taille de retour à la ligne invalide : {$size} base-common-read-error = erreur de lecture : {$error} +base-common-invalid-input = entrée invalide # Messages d'aide partagés de base_common base-common-help-decode = décoder les données diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 744eff55707..658debbf85c 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -643,6 +643,7 @@ pub mod fast_decode { use uucore::{ encoding::SupportsFastDecodeAndEncode, error::{UResult, USimpleError}, + translate, }; // Start of helper functions @@ -745,7 +746,10 @@ pub mod fast_decode { } else if ignore_garbage { continue; } else { - return Err(USimpleError::new(1, "error: invalid input")); + return Err(USimpleError::new( + 1, + translate!("base-common-invalid-input"), + )); } if supports_partial_decode { @@ -794,7 +798,10 @@ pub mod fast_decode { write_to_output(&mut decoded_buffer, output)?; if had_invalid_tail { - return Err(USimpleError::new(1, "error: invalid input")); + return Err(USimpleError::new( + 1, + translate!("base-common-invalid-input"), + )); } } @@ -857,7 +864,10 @@ pub mod fast_decode { buffer.drain(..decode_in_chunks_of_size); } } - return Err(USimpleError::new(1, "error: invalid input")); + return Err(USimpleError::new( + 1, + translate!("base-common-invalid-input"), + )); } if supports_partial_decode { @@ -909,7 +919,10 @@ pub mod fast_decode { write_to_output(&mut decoded_buffer, output)?; if had_invalid_tail { - return Err(USimpleError::new(1, "error: invalid input")); + return Err(USimpleError::new( + 1, + translate!("base-common-invalid-input"), + )); } } diff --git a/src/uucore/locales/en-US.ftl b/src/uucore/locales/en-US.ftl index d4aa0eb952d..6afc1ab7647 100644 --- a/src/uucore/locales/en-US.ftl +++ b/src/uucore/locales/en-US.ftl @@ -100,3 +100,7 @@ mode-diag-help-syntax = a mode is either octal, as in 644, or clauses such as u+ # Shared recursive chown/chgrp/chmod diagnostics (uucore::perms) perms-cannot-access = cannot access { $file }: { $error } perms-cannot-access-replaced = cannot access { $file }: replaced while it was being processed + +# Encoding/decoding error messages (base32, base64, basenc) +encoding-error-invalid-input = invalid input +encoding-error-invalid-input-z85-length = invalid input (length must be multiple of 4 characters) diff --git a/src/uucore/locales/fr-FR.ftl b/src/uucore/locales/fr-FR.ftl index 2b4ea26658c..80303701383 100644 --- a/src/uucore/locales/fr-FR.ftl +++ b/src/uucore/locales/fr-FR.ftl @@ -89,3 +89,7 @@ mode-error-invalid-operator = opérateur invalide (+, - ou = attendu, mais { $op mode-diag-label-missing-operator = cette clause indique qui, mais pas quoi changer mode-diag-label-invalid-number = n'est pas un mode octal mode-diag-help-syntax = un mode est soit octal, comme 644, soit des clauses comme u+rwx,go-w + +# Messages d'erreur d'encodage/décodage (base32, base64, basenc) +encoding-error-invalid-input = entrée invalide +encoding-error-invalid-input-z85-length = entrée invalide (la longueur doit être un multiple de 4 caractères) diff --git a/src/uucore/src/lib/features/encoding.rs b/src/uucore/src/lib/features/encoding.rs index 4a6e3394835..75e4eab61ff 100644 --- a/src/uucore/src/lib/features/encoding.rs +++ b/src/uucore/src/lib/features/encoding.rs @@ -8,6 +8,7 @@ // spell-checker:ignore ABCDEFGHJKLMNPQRSTUVWXY Zabcdefghijkmnopqrstuvwxyz use crate::error::{UResult, USimpleError}; +use crate::translate; use base64_simd; use data_encoding::Encoding; use data_encoding_macro::new_encoding; @@ -82,11 +83,15 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper { let segment_len = blocks * 4; if segment_len > remaining.len() { - return Err(USimpleError::new(1, "error: invalid input")); + return Err(USimpleError::new( + 1, + translate!("encoding-error-invalid-input"), + )); } - Self::decode_with_standard(&remaining[..segment_len], output) - .map_err(|_| USimpleError::new(1, "error: invalid input"))?; + Self::decode_with_standard(&remaining[..segment_len], output).map_err( + |_| USimpleError::new(1, translate!("encoding-error-invalid-input")), + )?; start += segment_len; } else { @@ -99,8 +104,9 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper { Self::decode_with_no_pad }; - decoder(remaining, output) - .map_err(|_| USimpleError::new(1, "error: invalid input"))?; + decoder(remaining, output).map_err(|_| { + USimpleError::new(1, translate!("encoding-error-invalid-input")) + })?; break; } @@ -109,7 +115,7 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper { Ok(()) } else { Self::decode_with_no_pad(input, output) - .map_err(|_| USimpleError::new(1, "error: invalid input")) + .map_err(|_| USimpleError::new(1, translate!("encoding-error-invalid-input"))) }; if let Err(err) = decode_result { @@ -287,7 +293,7 @@ impl SupportsFastDecodeAndEncode for Base58Wrapper { let digit = alphabet .iter() .position(|&b| b == byte) - .ok_or_else(|| USimpleError::new(1, "error: invalid input"))?; + .ok_or_else(|| USimpleError::new(1, translate!("encoding-error-invalid-input")))?; // Multiply by 58 and add digit let mut carry = digit as u32; @@ -418,11 +424,14 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper { fn decode_into_vec(&self, input: &[u8], output: &mut Vec) -> UResult<()> { if input.first() == Some(&b'#') { - return Err(USimpleError::new(1, "error: invalid input")); + return Err(USimpleError::new( + 1, + translate!("encoding-error-invalid-input"), + )); } - let decode_result = - z85::decode(input).map_err(|_de| USimpleError::new(1, "error: invalid input"))?; + let decode_result = z85::decode(input) + .map_err(|_de| USimpleError::new(1, translate!("encoding-error-invalid-input")))?; output.extend_from_slice(&decode_result); Ok(()) @@ -438,7 +447,7 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper { if !input.len().is_multiple_of(4) { return Err(USimpleError::new( 1, - "error: invalid input (length must be multiple of 4 characters)", + translate!("encoding-error-invalid-input-z85-length"), )); } @@ -464,7 +473,7 @@ impl SupportsFastDecodeAndEncode for EncodingWrapper { let decode_len_result = self .encoding .decode_len(input.len()) - .map_err(|_de| USimpleError::new(1, "error: invalid input"))?; + .map_err(|_de| USimpleError::new(1, translate!("encoding-error-invalid-input")))?; let output_len = output.len(); @@ -473,7 +482,7 @@ impl SupportsFastDecodeAndEncode for EncodingWrapper { let us = self .encoding .decode_mut(input, &mut (output[output_len..])) - .map_err(|_de| USimpleError::new(1, "error: invalid input"))?; + .map_err(|_de| USimpleError::new(1, translate!("encoding-error-invalid-input")))?; // See: // https://docs.rs/data-encoding/latest/data_encoding/struct.Encoding.html#method.decode_mut // "Returns the length of the decoded output. This length may be smaller than the output length if the input contained padding or ignored characters. The output bytes after the returned length are not initialized and should not be read." diff --git a/tests/by-util/test_base32.rs b/tests/by-util/test_base32.rs index 1816cb2927b..dac6c15509e 100644 --- a/tests/by-util/test_base32.rs +++ b/tests/by-util/test_base32.rs @@ -89,7 +89,7 @@ fn test_garbage() { .arg("-d") .pipe_in(input) .fails() - .stderr_only("base32: error: invalid input\n"); + .stderr_only("base32: invalid input\n"); } #[test] diff --git a/tests/by-util/test_base64.rs b/tests/by-util/test_base64.rs index e9d7da79362..3172a9930fb 100644 --- a/tests/by-util/test_base64.rs +++ b/tests/by-util/test_base64.rs @@ -155,7 +155,7 @@ fn test_garbage() { .arg("-d") .pipe_in(input) .fails() - .stderr_only("base64: error: invalid input\n"); + .stderr_only("base64: invalid input\n"); } #[test] diff --git a/tests/by-util/test_basenc.rs b/tests/by-util/test_basenc.rs index e4f2c3d3f84..4eb1b2fa42a 100644 --- a/tests/by-util/test_basenc.rs +++ b/tests/by-util/test_basenc.rs @@ -24,7 +24,7 @@ fn test_z85_not_padded_decode() { .args(&["--z85", "-d"]) .pipe_in("##########") .fails() - .stderr_only("basenc: error: invalid input\n"); + .stderr_only("basenc: invalid input\n"); } #[test] @@ -34,7 +34,7 @@ fn test_z85_not_padded_encode() { .args(&["--z85"]) .pipe_in("123") .fails() - .stderr_only("basenc: error: invalid input (length must be multiple of 4 characters)\n"); + .stderr_only("basenc: invalid input (length must be multiple of 4 characters)\n"); } #[test] @@ -147,7 +147,7 @@ fn test_base32_baddecode_keeps_prefix() { .pipe_in("MFRGGZDF=") .fails() .stdout_is("abcde") - .stderr_is("basenc: error: invalid input\n"); + .stderr_is("basenc: invalid input\n"); } #[test] @@ -166,7 +166,7 @@ fn test_base32hex_rejects_trailing_garbage() { .pipe_in("VNC0FKD5W") .fails() .stdout_is_bytes(b"\xFD\xD8\x07\xD1\xA5") - .stderr_is("basenc: error: invalid input\n"); + .stderr_is("basenc: invalid input\n"); } #[test] @@ -176,7 +176,7 @@ fn test_base32hex_truncated_block_keeps_prefix() { .pipe_in("CPNMUO") .fails() .stdout_is_bytes(b"foo") - .stderr_is("basenc: error: invalid input\n"); + .stderr_is("basenc: invalid input\n"); } #[test] diff --git a/util/build-gnu.sh b/util/build-gnu.sh index 53d3e9694d1..6979ddc3b27 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -280,9 +280,6 @@ sed -i -e "s|invalid suffix in --pages argument|invalid --pages argument|" \ sed -i "s/\(baddecode.*OUT=>\"\).*\"/\1\"/g" tests/basenc/base64.pl sed -i "s/\(\(b2[ml]_[69]\|z85_8\|z85_35\).*OUT=>\)[^}]*\(.*\)/\1\"\"\3/g" tests/basenc/basenc.pl -# add "error: " to the expected error message -sed -i "s/\$prog: invalid input/\$prog: error: invalid input/g" tests/basenc/basenc.pl - # basenc: swap out error message for unexpected arg sed -i "s/ {ERR=>\"\$prog: foobar\\\\n\" \. \$try_help }/ {ERR=>\"error: unexpected argument '--foobar' found\n\n tip: to pass '--foobar' as a value, use '-- --foobar'\n\nUsage: basenc [OPTION]... [FILE]\n\nFor more information, try '--help'.\n\"}]/" tests/basenc/basenc.pl sed -i "s/ {ERR_SUBST=>\"s\/(unrecognized|unknown) option \[-' \]\*foobar\[' \]\*\/foobar\/\"}],//" tests/basenc/basenc.pl