From 7b0fb8ce6f349ec6ce52c584184f4901a71a7368 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sun, 21 Dec 2025 22:54:32 +0100 Subject: [PATCH] u --- demo/capture-upload.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/demo/capture-upload.sh b/demo/capture-upload.sh index f099fd7..482c0e2 100755 --- a/demo/capture-upload.sh +++ b/demo/capture-upload.sh @@ -179,6 +179,17 @@ discover_and_report_controls() { log "Discovering available camera controls..." + # Helper function to escape strings for JSON + json_escape() { + local str="$1" + # Escape backslashes first, then quotes + str="${str//\\/\\\\}" + str="${str//\"/\\\"}" + # Remove any control characters + str=$(echo "$str" | tr -d '\n\r\t') + echo "$str" + } + # Parse v4l2-ctl -L output into JSON # Example lines: # brightness 0x00980900 (int) : min=-64 max=64 step=1 default=0 value=0 @@ -197,7 +208,7 @@ discover_and_report_controls() { while IFS= read -r line || [[ -n "$line" ]]; do # Check if this is a control line (starts with control name) - if [[ "$line" =~ ^[[:space:]]*([a-z_]+)[[:space:]]+0x[0-9a-f]+[[:space:]]+\(([a-z]+)\)[[:space:]]*:[[:space:]]*(.*) ]]; then + if [[ "$line" =~ ^[[:space:]]*([a-z_][a-z0-9_]*)[[:space:]]+0x[0-9a-f]+[[:space:]]+\(([a-z]+)\)[[:space:]]*:[[:space:]]*(.*) ]]; then # Save previous control if exists if [[ -n "$current_ctrl" ]]; then if [[ "$in_menu" == "true" && -n "$menu_options" ]]; then @@ -250,7 +261,8 @@ discover_and_report_controls() { # Check if this is a menu option line (indented with number: description) elif [[ "$in_menu" == "true" && "$line" =~ ^[[:space:]]+([0-9]+):[[:space:]]+(.+)$ ]]; then local opt_val="${BASH_REMATCH[1]}" - local opt_name="${BASH_REMATCH[2]}" + local opt_name + opt_name=$(json_escape "${BASH_REMATCH[2]}") menu_options+="\"$opt_val\": \"$opt_name\"," fi done < <(v4l2-ctl -d "$VIDEO_DEVICE" -L 2>/dev/null)