-
Notifications
You must be signed in to change notification settings - Fork 59
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
Don't try and hash if the data is empty #17
Conversation
Using Making this clearer while not panicking would really necessitate creating a new error enum wrapping So the two options (three in actuality but I'm very hesitant for the last one) would be:
As for your test, it looks all right but you don't need to use |
Or 4) Like 3), but without the yanking, and releasing as 2.0.0. It's unpleasant, but the best option given semantic versioning. |
Another option I was editing in before you replied would be to do what you're doing anyways, but just clearly document it. It's still misleading for people who don't read the documentation but it's not breaking and it eliminates the panic. |
assert!(decoded_result.is_err()); | ||
/* FIXME: Figure out how to make the below run | ||
match decoded_result { | ||
Err(FromBase64Error::InvalidBase64Length) => assert!(true), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert!()
is unnecessary for constant conditions. Just use ()
for assert!(true)
and panic!(...)
for assert!(false, ...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core problem I've got with the commented out lines is that they don't even compile. Any thoughts on how to fix that? I get
src/lib.rs:493:17: 493:53 error: unresolved enum variant, struct or const `InvalidBase64Length` [E0419]
src/lib.rs:493 Err(FromBase64Error::InvalidBase64Length) => (),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, you need to duplicate the import of FromBase64Error
in the sub-module.
In fact, you can just do use serialize::base64::*;
for both the test
submodule and the top level, since we're using a bunch of the definitions anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What might also be good would be to add pub use FromBase64Error;
to the top level so users who want to match on the error don't have to import from the rustc_serialize
crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if you were to do that, you'd need to have this at the top level:
use serialize::base64::{ToBase64, FromBase64, Config, STANDARD};
// Needs to be fully qualified
pub use serialize::base64::FromBase64Error;
And then the test
submodule can just have:
use serialize::base64::*;
Still a good idea though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! That was confusing the heck out of me, but now fixed
Publishing 2.0.0 feels yuckier than yanking 1.0.0 even though it follows the specification. |
Ultimately I think using |
I've fixed the test case and added a comment about the new error |
@@ -131,7 +132,7 @@ impl ImageHash { | |||
/// Create an `ImageHash` instance from the given Base64-encoded string. | |||
/// ## Note: | |||
/// **Not** compatible with Base64-encoded strings created before `HashType` was added. | |||
/// | |||
/// Returns a FromBase64Error::InvalidBase64Length when trying to hash a zero-length string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you format these docs like this?
/// Create an `ImageHash` instance from the given Base64-encoded string.
/// ## Note:
/// **Not** compatible with Base64-encoded strings created before `HashType` was added.
///
/// Does **not** preserve the internal value of `HashType::UserDCT`.
/// ## Errors:
/// Returns `FromBase64Error::InvalidBase64Length` when passed an empty string (`""`).
Thanks. (The empty line is intentional.)
Added a comment on the docs formatting, easy tweak. |
Done |
That'll work! I'll merge as soon as tests pass. I also need to fix the docs uploading but I probably won't do that tonight as it's really late here. |
Merged, thanks! |
I ran into a situation where I tried to push in a hash of a zero-length value, and instead of erroring, it paniced! This PR fixes the problem, but my Rust is still not very good so I haven't figured out how to write the test correctly. If anyone has any thoughts about how to fix the commented out code, that'd be much appreciated.