Add filename validation, rename some files

This commit is contained in:
Nick Ortakales 2025-02-26 16:56:43 -08:00
parent 13eb1e1a39
commit 6bec1893e6
9 changed files with 9 additions and 0 deletions

View file

@ -29,10 +29,19 @@ FORBIDDEN_PATTERNS=(
"Subtype: ([0-9]){2}" "Subtype: ([0-9]){2}"
) )
FILE_AND_DIR_ALLOWED_CHARACTERS="A-Za-z0-9().,!%&+ -";
FILE_AND_DIR_REGEX="^\.[$FILE_AND_DIR_ALLOWED_CHARACTERS/]+\/[$FILE_AND_DIR_ALLOWED_CHARACTERS]+\.nfc$"
# Use process substitution so that ERROR_FOUND is updated in the main shell. # Use process substitution so that ERROR_FOUND is updated in the main shell.
while read -r filename; do while read -r filename; do
content=$(cat "$filename") content=$(cat "$filename")
if ! echo "$filename" | awk "/$FILE_AND_DIR_REGEX/ { found=1 } END { exit !found }"; then
echo "$filename"
echo " Filename has invalid characters or missing .nfc extension. Allowed characters are $FILE_AND_DIR_ALLOWED_CHARACTERS"
ERROR_FOUND=1
fi
for pattern in "${REQUIRED_PATTERNS[@]}"; do for pattern in "${REQUIRED_PATTERNS[@]}"; do
if ! echo "$content" | awk "/$pattern/ { found=1 } END { exit !found }"; then if ! echo "$content" | awk "/$pattern/ { found=1 } END { exit !found }"; then
echo "$filename" echo "$filename"