-
Notifications
You must be signed in to change notification settings - Fork 7
t2929: Fix config-helper.sh _jsonc_get discards false values #2934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -233,13 +233,17 @@ _jsonc_get() { | |||||
| merged=$(_get_merged_config) | ||||||
|
|
||||||
| # Use jq --arg to safely pass dotpath (no shell interpolation into filter) | ||||||
| local value | ||||||
| value=$(echo "$merged" | jq -r --arg p "$dotpath" 'getpath($p | split(".")) // empty' 2>/dev/null) || value="" | ||||||
| # NOTE: We must NOT use jq's `// empty` alternative operator here because | ||||||
| # it treats `false` and `null` the same (both are falsy in jq). Instead, | ||||||
| # get the raw JSON value and check for null explicitly in bash. | ||||||
| local raw_value | ||||||
| raw_value=$(echo "$merged" | jq --arg p "$dotpath" 'getpath($p | split("."))' 2>/dev/null) || raw_value="null" | ||||||
|
|
||||||
| if [[ -n "$value" && "$value" != "null" ]]; then | ||||||
| echo "$value" | ||||||
| else | ||||||
| if [[ "$raw_value" == "null" ]]; then | ||||||
| echo "$default" | ||||||
| else | ||||||
| # Use jq -r to strip quotes from strings; booleans/numbers pass through as-is | ||||||
| echo "$raw_value" | jq -r '.' | ||||||
| fi | ||||||
| return 0 | ||||||
| } | ||||||
|
|
@@ -261,7 +265,14 @@ _jsonc_get_raw() { | |||||
| echo "" | ||||||
| return 0 | ||||||
| } | ||||||
| echo "$json" | jq -r --arg p "$dotpath" 'getpath($p | split(".")) // empty' 2>/dev/null || echo "" | ||||||
| # Avoid `// empty` — it discards false and 0 (falsy in jq). Check for null explicitly. | ||||||
| local raw_value | ||||||
| raw_value=$(echo "$json" | jq --arg p "$dotpath" 'getpath($p | split("."))' 2>/dev/null) || raw_value="null" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, removing
Suggested change
References
|
||||||
| if [[ "$raw_value" == "null" ]]; then | ||||||
| echo "" | ||||||
| else | ||||||
| echo "$raw_value" | jq -r '.' | ||||||
| fi | ||||||
| return 0 | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -486,7 +497,14 @@ cmd_list() { | |||||
|
|
||||||
| local user_val env_val effective source | ||||||
|
|
||||||
| user_val=$(echo "$user_json" | jq -r --arg p "$dotpath" 'getpath($p | split(".")) // empty' 2>/dev/null) || user_val="" | ||||||
| # Get raw JSON value to distinguish null (absent) from false/0 | ||||||
| local raw_user_val | ||||||
| raw_user_val=$(echo "$user_json" | jq --arg p "$dotpath" 'getpath($p | split("."))' 2>/dev/null) || raw_user_val="null" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To align with repository guidelines and improve debugging, please remove the
Suggested change
References
|
||||||
| if [[ "$raw_user_val" == "null" ]]; then | ||||||
| user_val="" | ||||||
| else | ||||||
| user_val=$(echo "$raw_user_val" | jq -r '.') | ||||||
| fi | ||||||
|
|
||||||
| # Check env override | ||||||
| env_val="" | ||||||
|
|
@@ -500,7 +518,7 @@ cmd_list() { | |||||
| if [[ -n "$env_val" ]]; then | ||||||
| effective="$env_val" | ||||||
| source="env" | ||||||
| elif [[ -n "$user_val" ]]; then | ||||||
| elif [[ "$raw_user_val" != "null" ]]; then | ||||||
| effective="$user_val" | ||||||
| source="user" | ||||||
| else | ||||||
|
|
@@ -579,17 +597,18 @@ cmd_set() { | |||||
| # Validate dotpath contains only safe characters | ||||||
| _validate_dotpath "$dotpath" || return 1 | ||||||
|
|
||||||
| # Validate key exists in defaults | ||||||
| # Validate key exists in defaults (use raw JSON to distinguish null from false/0) | ||||||
| local defaults_json | ||||||
| defaults_json=$(_strip_jsonc "$JSONC_DEFAULTS") || return 1 | ||||||
| local default_val | ||||||
| default_val=$(echo "$defaults_json" | jq -r --arg p "$dotpath" 'getpath($p | split(".")) // empty' 2>/dev/null) || default_val="" | ||||||
| local raw_default_val default_val | ||||||
| raw_default_val=$(echo "$defaults_json" | jq --arg p "$dotpath" 'getpath($p | split("."))' 2>/dev/null) || raw_default_val="null" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the
Suggested change
References
|
||||||
|
|
||||||
| if [[ -z "$default_val" ]]; then | ||||||
| if [[ "$raw_default_val" == "null" ]]; then | ||||||
| echo "[ERROR] Unknown config key: $dotpath" >&2 | ||||||
| echo " Run 'aidevops config list' to see available options." >&2 | ||||||
| return 1 | ||||||
| fi | ||||||
| default_val=$(echo "$raw_default_val" | jq -r '.') | ||||||
|
|
||||||
| # Validate value type from default and reject invalid input early | ||||||
| case "$default_val" in | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This correctly fixes the issue with
falsevalues. However, using2>/dev/nullsuppresses potentially useful error messages fromjq, for instance if the configuration file contains invalid JSON. This goes against a general rule for this repository. Since you're already handling the error case with|| raw_value="null", you can safely remove the stderr redirection to improve debuggability.References