Skip to content

Commit

Permalink
Remove registry clean_string hack (nushell#10804)
Browse files Browse the repository at this point in the history
# Description

Remove the `clean_string` hack used in `registry query`.

This was a workaround for a [bug][gentoo90/winreg-rs#52] in winreg which
has since [been fixed][edf9eef] and released in [winreg v0.12.0].

winreg now properly displays strings in RegKey's Display impl instead of
outputting their debug representation. We remove our `clean_string` such
that registry entries which happen to start/end with `"` or contain `\\`
won't get mangled. This is very important for entries in UNC path format
as those begin with a double backslash.

[gentoo90/winreg-rs#52]:
<gentoo90/winreg-rs#52>
[edf9eef]:
<gentoo90/winreg-rs@edf9eef>
[winreg v0.12.0]:
<https://github.com/gentoo90/winreg-rs/releases/tag/v0.12.0>

# User-Facing Changes

- `registry query` used to accidentally mangle values that contain a
literal `\\`, such as UNC paths. It no longer does so.

# Tests + Formatting

- [X] `toolkit check pr`
  - 🟢 `toolkit fmt`
  - 🟢 `toolkit clippy`
  - 🟢 `toolkit test`
  - 🟢 `toolkit test stdlib`
  • Loading branch information
CAD97 authored Oct 21, 2023
1 parent 6445c4e commit a01ef85
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions crates/nu-command/src/system/registry_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,18 @@ fn get_reg_hive(call: &Call) -> Result<RegKey, ShellError> {
Ok(RegKey::predef(hkey))
}

fn clean_string(string: &str) -> String {
string
.trim_start_matches('"')
.trim_end_matches('"')
.replace("\\\\", "\\")
}
fn reg_value_to_nu_value(
reg_value: winreg::RegValue,
call_span: Span,
) -> (nu_protocol::Value, winreg::enums::RegType) {
match reg_value.vtype {
REG_NONE => (Value::nothing(call_span), reg_value.vtype),
REG_SZ => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_EXPAND_SZ => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_BINARY => (Value::binary(reg_value.bytes, call_span), reg_value.vtype),
Expand All @@ -210,23 +204,23 @@ fn reg_value_to_nu_value(
reg_value.vtype,
),
REG_LINK => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_MULTI_SZ => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_RESOURCE_LIST => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_FULL_RESOURCE_DESCRIPTOR => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_RESOURCE_REQUIREMENTS_LIST => (
Value::string(clean_string(&reg_value.to_string()), call_span),
Value::string(reg_value.to_string(), call_span),
reg_value.vtype,
),
REG_QWORD => (
Expand Down

0 comments on commit a01ef85

Please sign in to comment.