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

Handle quotes and backslashes in item names #52

Closed
wants to merge 1 commit into from

Conversation

diogotito
Copy link
Contributor

@diogotito diogotito commented Jun 20, 2020

Fixes #35

My vault has an item that has quotes in the name, and it derails bwmenu in a way that forces me to pkill bwmenu

I found that the problem is that the item and folder names are being directly used in some jq filters, artificially wrapped in quotes, like this:

select(.name == \"$item_name\")

If $item_name has quotes or backslashes, its expansion will create a jq syntax error.

I found this solution on StackOverflow that makes jq slurp a string like $item_name from stdin and output the correctly JSON-encoded version of it, and decided to incorporate it in the script.

select(.name == $(echo -n "$item_name" | jq -Rs))

I am confident that bitwarden-rofi will now be capable of handling the weirdest item names and folder names we can put in our vaults!


PS: I made an alternative branch where my jq_escape function gets the input string from stdin, but I'm afraid it makes the code that uses it a little harder to understand. It also shows that jq_escape is a bit useless by itself, but I believe it make it more obvious what's happening to the names.

The item names are being copied inside a jq string literal without being
properly escaped, which causes problems when the names have quotes,
backslashes or other weird characters in them.

The optimal way to escape these names seems to be using jq itself to
generate its own string literals.
Copy link
Contributor

@Mange Mange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks great!

@mattydebie
Copy link
Owner

mattydebie commented Jun 20, 2020 via email

@mattydebie
Copy link
Owner

Thanks! merge in db3427d

@mattydebie mattydebie closed this Apr 14, 2023
@diogotito diogotito deleted the jq-escape-param branch April 15, 2023 00:28
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

Successfully merging this pull request may close these issues.

Fails on entries with backslash
3 participants