Skip to content

Provide defaults for missing JOB values #28

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

Merged

Conversation

weierophinney
Copy link
Member

As reported in Slack, if a value is missing, jq returns null. When run normally (e.g., echo "${JOB}" | jq -r '.somekey'), this becomes an empty string when the key is missing. However, when run within a subshell (e.g., when assigning to a variable, such as VALUE=$(echo "${JOB}" | jq -r '.somekey')), the string null is returned.

Fortunately, jq allows specifying an alternative value if a value is missing or false or null, via the // operator. This patch adds alternatives everywhere jq is invoked when assigning a variable.

As reported in Slack, if a value is missing, `jq` returns `null`.
When run normally (e.g., `echo "${JOB}" | jq -r '.somekey'`), this becomes an empty string when the key is missing.
However, when run within a subshell (e.g., when assigning to a variable, such as `VALUE=$(echo "${JOB}" | jq -r '.somekey')`), the string `null` is returned.

Fortunately, `jq` allows specifying an alternative value if a value is missing or `false` or `null`, via the `//` operator.
This patch adds alternatives everywhere `jq` is invoked when assigning a variable.

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
@weierophinney weierophinney added this to the 1.6.2 milestone Apr 9, 2021
@weierophinney weierophinney added the Bug Something isn't working label Apr 9, 2021
@weierophinney weierophinney merged commit 21c0b0f into laminas:1.6.x Apr 9, 2021
@weierophinney weierophinney deleted the hotfix/cast-null-to-empty-string branch April 9, 2021 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant