Handle quotes and backslashes in item names #52
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #35
My vault has an item that has quotes in the name, and it derails
bwmenu
in a way that forces me topkill 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:
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.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 thatjq_escape
is a bit useless by itself, but I believe it make it more obvious what's happening to the names.