doy / rbw

unofficial bitwarden cli

Home Page:https://git.tozt.net/rbw

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to `get` entries containing colons in the name

sareyko opened this issue · comments

Ever since implementing URI matching (see a864366) trying to get entries containing a colon : in the name field fails.

Example

$ rbw list
...
Example: not an URI
...

$ rbw get 'Example: not an URI'
rbw get: couldn't find entry for 'example: not an URI': no entry found

Note how the error message lower cases the string preceding the colon.

More details

Separating "Example" from the colon in the name yields the desired results:

$ rbw list
...
Example : not an URI
...

$ rbw get 'Example : not an URI'
secret

Cause

After digging through the code and having a play with Rusts url crate I'm pretty sure the issue lies in the usage of Url::parse() in parse_needle() to determine if the given string is (an UUID,) an URL or just a name.

pub fn parse_needle(arg: &str) -> Result<Needle, std::convert::Infallible> {
if let Ok(uuid) = uuid::Uuid::parse_str(arg) {
return Ok(Needle::Uuid(uuid));
}
if let Ok(url) = Url::parse(arg) {
return Ok(Needle::Uri(url));
}
Ok(Needle::Name(arg.to_string()))
}

Url::parse() seems to return Ok for every string not containing any whitespace that is followed by a colon and optional text.

Here's a link to Rust Playground containing some example strings to run throug Url::parse(): https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4b84a31eaa0520308fcf6c6a0095f6e9

Possible solution

I can't think of a good solution to the problem other than maybe implementing a fallback mechanism that treats the first argument given to get as name when an URL (according to Url::parse()) is detected but no entry with this URL is found.

hopefully fixed in bd2c93e - let me know if this still comes up