From 876d6bcd2343cd2f8191d3d55aab7e8219a27c7f Mon Sep 17 00:00:00 2001 From: Kyunghyun Park Date: Sat, 25 Jul 2026 01:33:30 +0900 Subject: [PATCH] Fix bar plugin JSON value validation --- bin/omarchy-bar-plugin | 2 +- test/shell.d/config-test.sh | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bin/omarchy-bar-plugin b/bin/omarchy-bar-plugin index 19fabef2..925acaf7 100755 --- a/bin/omarchy-bar-plugin +++ b/bin/omarchy-bar-plugin @@ -420,7 +420,7 @@ cmd_set() { parse_placement "$@" if [[ $value_is_json == "true" ]]; then - jq -e . <<<"$value" >/dev/null 2>&1 || fail "invalid JSON value: $value" + jq -n --argjson value "$value" empty >/dev/null 2>&1 || fail "invalid JSON value: $value" fi local value_arg diff --git a/test/shell.d/config-test.sh b/test/shell.d/config-test.sh index 6a036c1a..773d5d2d 100755 --- a/test/shell.d/config-test.sh +++ b/test/shell.d/config-test.sh @@ -289,6 +289,28 @@ jq -e ' ' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null pass "shell config removes widgets with remove alias" +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin set omarchy.bluetooth enabled false --json +jq -e ' + any(.bar.layout.right[]; .id == "omarchy.bluetooth" and .enabled == false) +' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null +pass "bar plugin set accepts false JSON values" + +HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin set omarchy.bluetooth optional null --json +jq -e ' + any(.bar.layout.right[]; .id == "omarchy.bluetooth" and has("optional") and .optional == null) +' "$TMPDIR/home/.config/omarchy/shell.json" >/dev/null +pass "bar plugin set accepts null JSON values" + +if HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin set omarchy.bluetooth broken '{' --json 2>/dev/null; then + fail "bar plugin set accepted malformed JSON" +fi +pass "bar plugin set rejects malformed JSON" + +if HOME="$TMPDIR/home" OMARCHY_PATH="$ROOT" omarchy-bar-plugin set omarchy.bluetooth broken 'false null' --json 2>/dev/null; then + fail "bar plugin set accepted multiple JSON values" +fi +pass "bar plugin set rejects multiple JSON values" + mock_bin="$TMPDIR/mock-bin" mkdir -p "$mock_bin"