Properly escape everywhere

This commit is contained in:
Lukáš Kucharczyk 2022-11-16 12:43:06 +01:00
parent 76b490bc83
commit e00766cce8
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 7 additions and 7 deletions

14
tag.sh
View File

@ -16,7 +16,7 @@ set -ueo pipefail
# TODO: adjust sqlite_insert_multiple to allow defining columns per insert, currently it's hardcoded to 2 # TODO: adjust sqlite_insert_multiple to allow defining columns per insert, currently it's hardcoded to 2
# TODO: merge sqlite_insert_single and sqlite_insert_multiple probably as result of the above # TODO: merge sqlite_insert_single and sqlite_insert_multiple probably as result of the above
SCRIPT_DIR=$(dirname $(readlink "$0")) SCRIPT_DIR=$(dirname "$(readlink "$0")")
SCRIPT_NAME=$(basename "$0") SCRIPT_NAME=$(basename "$0")
@ -152,10 +152,10 @@ add_path() {
for FILE in "$@"; do for FILE in "$@"; do
[ ! -f "$FILE" ] && fail "File '$FILE' does not exist in the specified path." [ ! -f "$FILE" ] && fail "File '$FILE' does not exist in the specified path."
local FILENAME=$(basename "$FILE") local FILENAME=$(basename "$FILE")
local FILEPATH=$(realpath $(dirname "$FILE")) local FILEPATH=$(realpath "$(dirname "$FILE")")
file_exists_in_db "$FILE" && fail "File '$FILE' already exists in database." file_exists_in_db "$FILE" && fail "File '$FILE' already exists in database."
FILES+=("'$FILENAME'") FILES+=("\"$FILENAME\"")
FILES+=("'$FILEPATH'") FILES+=("\"$FILEPATH\"")
done done
sqlite_insert_multi "$TABLE" "$COLUMN" "${FILES[@]}" sqlite_insert_multi "$TABLE" "$COLUMN" "${FILES[@]}"
} }
@ -179,7 +179,7 @@ add_path_auto() {
tag_exists_in_db() { tag_exists_in_db() {
# $TAGLABEL # $TAGLABEL
TAG=${1:-} TAG=${1:-}
RESULT=$(sqlite_query "SELECT id FROM tags WHERE label = '$TAG'") RESULT=$(sqlite_query "SELECT id FROM tags WHERE label = \"$TAG\"")
if [[ -z "$RESULT" ]]; then if [[ -z "$RESULT" ]]; then
return 1 return 1
else else
@ -200,9 +200,9 @@ file_exists_in_db() {
file_by_filename() { file_by_filename() {
# FILENAME # FILENAME
local FILENAME=$(basename "${1:-}") local FILENAME=$(basename "${1:-}")
local FILEPATH=$(realpath $(dirname "${1:-}")) local FILEPATH=$(realpath "$(dirname "${1:-}")")
local RESULT=0 local RESULT=0
RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = '$FILENAME' AND path = '$FILEPATH'") RESULT=$(sqlite_query "SELECT id FROM files WHERE filename = \"$FILENAME\" AND path = \"$FILEPATH\"")
echo $RESULT echo $RESULT
} }