Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/otp/from_otp_uri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub trait FromOtpUri: Sized {

impl FromOtpUri for OTPElement {
fn from_otp_uri(otp_uri: &str) -> color_eyre::Result<Self> {
let parsed_uri = Url::parse(otp_uri).map_err(ErrReport::from)?;
let decoded = urlencoding::decode(otp_uri).map_err(ErrReport::from)?;
let parsed_uri = Url::parse(&decoded).map_err(ErrReport::from)?;

let otp_type = parsed_uri
.host_str()
Expand Down
30 changes: 30 additions & 0 deletions src/otp/otp_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,34 @@ mod test {
result.unwrap_err().to_string()
);
}

#[test]
fn gh_issue_548_invalid_otp_uri_label_url_encoded() {
// Arrange
let otp_uri = "otpauth://totp/foo%3abar?issuer=foo&secret=JBSWY3DPEHPK3PXP";

// Act
let result = OTPElement::from_otp_uri(otp_uri);

// Assert
assert!(result.is_ok());
let actual = result.unwrap();
assert_eq!("foo", actual.issuer.as_str());
assert_eq!("bar", actual.label.as_str());
}

#[test]
fn gh_issue_548_invalid_otp_uri_label_non_url_encoded() {
// Arrange
let otp_uri = "otpauth://totp/foo:bar?issuer=foo&secret=JBSWY3DPEHPK3PXP";

// Act
let result = OTPElement::from_otp_uri(otp_uri);

// Assert
assert!(result.is_ok());
let actual = result.unwrap();
assert_eq!("foo", actual.issuer.as_str());
assert_eq!("bar", actual.label.as_str());
}
}
Loading