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

[rust] Make Debug implementation for Uri use percent encoding #3

Open
not-my-profile opened this issue Nov 10, 2021 · 0 comments
Open

Comments

@not-my-profile
Copy link

not-my-profile commented Nov 10, 2021

Currently the Uri struct is defined as follows:

#[derive(Clone, Debug, Default, PartialEq)]
pub struct Uri {
    scheme: Option<String>,
    authority: Option<Authority>,
    path: Vec<Vec<u8>>,
    query: Option<Vec<u8>>,
    fragment: Option<Vec<u8>>,
}

Which results in path, query and fragment being printed as number arrays in debug mode e.g. println!("{:?}", Uri::parse("test")); results in:

Ok(Uri { scheme: None, authority: None, path: [[116, 101, 115, 116]], query: None, fragment: None })

I would find the debug output more readable if path, query and fragment were printed in percent-encoding.

If you think this is a good idea, I'm happy to send a pull request.

not-my-profile added a commit to not-my-profile/Uri that referenced this issue Nov 14, 2021
Previously an assertion like:

  assert_eq!(Uri::parse("some/path"), Uri::parse("other/path"));

resulted in a panic like:

thread 'uri::tests::example' panicked at 'assertion failed: `(left == right)`
  left: `Ok(Uri { scheme: None, authority: None, path: [[115, 111, 109, 101], [112, 97, 116, 104]], query: None, fragment: None })`,
 right: `Ok(Uri { scheme: None, authority: None, path: [[111, 116, 104, 101, 114], [112, 97, 116, 104]], query: None, fragment: None })`'

This commit changes the Debug impl to be more developer friendly:

thread 'uri::tests::foobar' panicked at 'assertion failed: `(left == right)`
  left: `Ok(Uri("some/path"))`,
 right: `Ok(Uri("other/path"))`'

Fixes rhymu8354#3.
not-my-profile added a commit to not-my-profile/Uri that referenced this issue Nov 14, 2021
Previously an assertion like:

  assert_eq!(Uri::parse("some/path"), Uri::parse("other/path"));

resulted in a panic like:

thread 'uri::tests::example' panicked at 'assertion failed: `(left == right)`
  left: `Ok(Uri { scheme: None, authority: None, path: [[115, 111, 109, 101], [112, 97, 116, 104]], query: None, fragment: None })`,
 right: `Ok(Uri { scheme: None, authority: None, path: [[111, 116, 104, 101, 114], [112, 97, 116, 104]], query: None, fragment: None })`'

This commit changes the Debug impl to be more developer friendly:

thread 'uri::tests::example' panicked at 'assertion failed: `(left == right)`
  left: `Ok(Uri("some/path"))`,
 right: `Ok(Uri("other/path"))`'

Fixes rhymu8354#3.
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