Skip to content

Commit 835d1e5

Browse files
fix(state): read jq-pretty-printed array values from the state file
get_state_value() matched with a single-line sed that broke on the jq-pretty-printed state file, where array values span multiple lines and `[...]` never matched. Flatten the state (newlines/tabs -> spaces) before matching, then: - array values are returned as one-line JSON with element quotes intact, so callers can test membership against the exact quoted element; - scalar values stay unquoted as before. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2861591 commit 835d1e5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

scripts/lib/state.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,8 +928,19 @@ state_get() {
928928
# Basic fallback for simple keys (no nested paths)
929929
# This is a simplified parser - prefer having jq installed
930930
# Uses sed instead of grep -oP for POSIX compatibility (macOS, BSD)
931+
# The state file is jq-pretty-printed (arrays span lines), so flatten
932+
# before matching. Array values are returned as one-line JSON with the
933+
# element quotes intact so callers can test membership against the
934+
# exact quoted element; scalar values are returned unquoted.
931935
local simple_key="${key#.}"
932-
echo "$state" | sed -n "s/.*\"${simple_key}\"[[:space:]]*:[[:space:]]*\([^,}]*\).*/\1/p" | tr -d '"' | head -1
936+
local flat array_value
937+
flat="$(printf '%s' "$state" | tr '\n\t' ' ')"
938+
array_value="$(printf '%s' "$flat" | sed -n "s/.*\"${simple_key}\"[[:space:]]*:[[:space:]]*\(\[[^]]*\]\).*/\1/p")"
939+
if [[ -n "$array_value" ]]; then
940+
printf '%s\n' "$array_value"
941+
else
942+
printf '%s' "$flat" | sed -n "s/.*\"${simple_key}\"[[:space:]]*:[[:space:]]*\([^,}]*\).*/\1/p" | tr -d '"' | head -1
943+
fi
933944
fi
934945
}
935946

0 commit comments

Comments
 (0)