Skip to content

Commit c949d2e

Browse files
authored
into string should not modify strings (nushell#15320)
# Description `into string` should not modify input strings (even with the `--group-digits` flag). It's a conversion command, not a formatting command. # User-Facing Changes - For strings, the same behavior from 0.102.0 is preserved. - Errors are no longer turned into strings, but rather they are returned as is. # After Submitting Create a `format int` and/or `format float` command and so that the `--group-digits` flag can be transferred to one of those commands.
1 parent 83de856 commit c949d2e

File tree

2 files changed

+4
-18
lines changed
  • crates
    • nu-command/src/conversions/into
    • nu-protocol/src/errors/shell_error

2 files changed

+4
-18
lines changed

crates/nu-command/src/conversions/into/string.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use nu_cmd_base::input_handler::{operate, CmdArgument};
22
use nu_engine::command_prelude::*;
3-
use nu_protocol::{shell_error::into_code, Config};
3+
use nu_protocol::Config;
44
use nu_utils::get_system_locale;
55
use num_format::ToFormattedString;
66
use std::sync::Arc;
@@ -215,17 +215,8 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
215215
}
216216
Value::Bool { val, .. } => Value::string(val.to_string(), span),
217217
Value::Date { val, .. } => Value::string(val.format("%c").to_string(), span),
218-
Value::String { val, .. } => {
219-
if group_digits {
220-
let number = val.parse::<i64>().unwrap_or_default();
221-
let decimal_value = digits.unwrap_or(0) as usize;
222-
Value::string(format_int(number, group_digits, decimal_value), span)
223-
} else {
224-
Value::string(val.to_string(), span)
225-
}
226-
}
227-
Value::Glob { val, .. } => Value::string(val.to_string(), span),
228-
218+
Value::String { val, .. } => Value::string(val, span),
219+
Value::Glob { val, .. } => Value::string(val, span),
229220
Value::Filesize { val, .. } => {
230221
if group_digits {
231222
let decimal_value = digits.unwrap_or(0) as usize;
@@ -235,8 +226,6 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
235226
}
236227
}
237228
Value::Duration { val: _, .. } => Value::string(input.to_expanded_string("", config), span),
238-
239-
Value::Error { error, .. } => Value::string(into_code(error).unwrap_or_default(), span),
240229
Value::Nothing { .. } => Value::string("".to_string(), span),
241230
Value::Record { .. } => Value::error(
242231
// Watch out for CantConvert's argument order
@@ -272,6 +261,7 @@ fn action(input: &Value, args: &Arguments, span: Span) -> Value {
272261
})
273262
.unwrap_or_else(|err| Value::error(err, span))
274263
}
264+
Value::Error { .. } => input.clone(),
275265
x => Value::error(
276266
ShellError::CantConvert {
277267
to_type: String::from("string"),

crates/nu-protocol/src/errors/shell_error/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,10 +1474,6 @@ impl<'de> Deserialize<'de> for ShellError {
14741474
}
14751475
}
14761476

1477-
pub fn into_code(err: &ShellError) -> Option<String> {
1478-
err.code().map(|code| code.to_string())
1479-
}
1480-
14811477
#[test]
14821478
fn shell_error_serialize_roundtrip() {
14831479
// Ensure that we can serialize and deserialize `ShellError`, and check that it basically would

0 commit comments

Comments
 (0)