Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/base32/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/uu/base32/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ pub mod fast_decode {
use uucore::{
encoding::SupportsFastDecodeAndEncode,
error::{UResult, USimpleError},
translate,
};

// Start of helper functions
Expand Down Expand Up @@ -729,7 +730,10 @@ pub mod fast_decode {
} else if ignore_garbage {
continue;
} else {
return Err(USimpleError::new(1, "error: invalid input"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHould be localised

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localised as base-common-invalid-input in base_common.rs/.ftl, sha a8d7da6.

return Err(USimpleError::new(
1,
translate!("base-common-invalid-input"),
));
}

if supports_partial_decode {
Expand Down Expand Up @@ -778,7 +782,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"),
));
}
}

Expand Down Expand Up @@ -841,7 +848,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 {
Expand Down Expand Up @@ -893,7 +903,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"),
));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/uucore/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ mode-error-invalid-operator = invalid operator (expected +, -, or =, but found {
mode-diag-label-missing-operator = this clause says who, but not what to change
mode-diag-label-invalid-number = not an octal mode
mode-diag-help-syntax = a mode is either octal, as in 644, or clauses such as u+rwx,go-w

# 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)
4 changes: 4 additions & 0 deletions src/uucore/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,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)
35 changes: 22 additions & 13 deletions src/uucore/src/lib/features/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -418,11 +424,14 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper {

fn decode_into_vec(&self, input: &[u8], output: &mut Vec<u8>) -> 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(())
Expand All @@ -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)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be localised too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localised as encoding-error-invalid-input/encoding-error-invalid-input-z85-length in uucore/encoding.rs/.ftl, sha a8d7da6.

translate!("encoding-error-invalid-input-z85-length"),
));
}

Expand All @@ -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();

Expand All @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_base32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions tests/by-util/test_basenc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
3 changes: 0 additions & 3 deletions util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,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
Expand Down
Loading