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
Closed
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
4 changes: 2 additions & 2 deletions bwmenu
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ show_folders() {
folders=$(bw list folders --session "$BW_HASH")
if folder=$(echo "$folders" | jq -r '.[] | .name' | rofi_menu); then

folder_id=$(echo "$folders" | jq -r ".[] | select(.name == \"$folder\").id")
folder_id=$(echo "$folders" | jq -r ".[] | select(.name == $(jq_escape "$folder")).id")

ITEMS=$(bw list items --folderid "$folder_id" --session "$BW_HASH")
show_items
else
rofi_exit_code="$?"
folder_id=$(echo "$folders" | jq -r ".[] | select(.name == \"$folder\").id")
folder_id=$(echo "$folders" | jq -r ".[] | select(.name == $(jq_escape "$folder")).id")
item_array=$(bw list items --folderid "$folder_id" --session "$BW_HASH")
on_rofi_exit "$rofi_exit_code" "$item_array"
fi
Expand Down
12 changes: 9 additions & 3 deletions lib-bwmenu
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/bin/bash
# Helper functions

# Escape the argument into a valid jq string literal (with quotes included)
# $1: string to escape
jq_escape() {
echo -n "$1" | jq -Rs
}

# Extract item or items matching .name, including deduplication
# $1: item name, prepended or not with deduplication mark
array_from_name() {
item_name="$(echo "$1" | sed "s/$DEDUP_MARK //")"
echo "$ITEMS" | jq -r ". | map(select((.name == \"$item_name\") and (.type == $TYPE_LOGIN)))"
item_name=$(jq_escape "${1#$DEDUP_MARK }")
echo "$ITEMS" | jq -r "map(select((.name == $item_name) and (.type == $TYPE_LOGIN)))"
}

# Extract item matching .id
# $1: string starting with ".id:"
array_from_id() {
echo "$ITEMS" | jq -r ". | map(select(.id == \"$1\"))"
echo "$ITEMS" | jq -r ". | map(select(.id == $(jq_escape $1)))"
}

# Count the number of items in an array. Return true if more than 1 or none
Expand Down