Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegValue.to_string() unexpectedly escapes forward slashes #52

Closed
smacdo opened this issue May 23, 2023 · 0 comments
Closed

RegValue.to_string() unexpectedly escapes forward slashes #52

smacdo opened this issue May 23, 2023 · 0 comments

Comments

@smacdo
Copy link

smacdo commented May 23, 2023

I ran into an issue that I think is unexpected (or at least undocumented) behavior. I needed to convert a RegValue to a String when enumerating values, and the following happened:

        Ok(regkey
            .enum_values()
            .map(|r| {
                let (key, val) = r.unwrap();
                (key, val.to_string())
            })
            .collect::<HashMap<_, _>>())

val ends up containing values like: "C:\foo\bar" rather than C:\foo\bar which is what the registry had.

If I instead use the trait FromRegValue then I get my expected C:\foo\bar:

        Ok(regkey
            .enum_values()
            .map(|r| {
                let (key, val) = r.unwrap();

                (
                    key,
                    String::from_reg_value(&val)
                        .expect("failed to convert regkey OsStr to String"),
                )
            })
            .collect::<HashMap<_, _>>())

Also, is there a way to convert from RegValue to String using Into<String> rather than the custom trait? That would be nice too. I could also be misunderstanding how to use this crate as well.

gentoo90 added a commit that referenced this issue Jul 30, 2023
Use `Display` instead of `Debug` for string and numeric values

Fixes #52
CAD97 added a commit to CAD97/nushell that referenced this issue Oct 21, 2023
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>
fdncred pushed a commit to nushell/nushell that referenced this issue Oct 21, 2023
# 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`
hardfau1t pushed a commit to hardfau1t/nushell that referenced this issue Dec 14, 2023
# 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant