Skip to content

Commit 20a221a

Browse files
authored
Fix multiline environment variables with jq -s (#17)
When converting raw strings to JSON. Fixes #15
1 parent c158227 commit 20a221a

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

bash-env-json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
2424

25-
VERSION="0.10.0a1"
25+
VERSION="0.10.0a2"
2626
USAGE="bash-env-json [--help] [--shellfns <comma-separated-function-names>] [path]"
2727

2828
shopt -s extglob
@@ -63,7 +63,7 @@ function capture() {
6363
function emit_value() {
6464
# `jq -R` produces nothing on empty input, but we want ""
6565
if test -n "$1"; then
66-
echo -n "$1" | _jq -R
66+
echo -n "$1" | _jq -Rs
6767
else
6868
echo -n '""'
6969
fi

tests.bats

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function test_case() {
1313
echo "$@"
1414

1515
# sort and remove `meta` before comparison with expected output
16-
bash-env-json "$@" "$_test_file" | jq --sort-keys 'del(.meta)' | diff -w - "$_expected_output"
16+
./bash-env-json "$@" "$_test_file" | jq --sort-keys 'del(.meta)' | diff -w - "$_expected_output"
1717
}
1818

1919
@test "empty" {
@@ -40,11 +40,14 @@ function test_case() {
4040
test_case "Ming's menu of (merciless) monstrosities"
4141
}
4242

43+
@test "multiline-string" {
44+
test_case multiline-string
45+
}
46+
4347
@test "error" {
4448
test_case error
4549
}
4650

47-
4851
@test "shell-function-error" {
4952
test_case shell-function-error --shellfns f
5053
}

tests/multiline-string.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export MULTILINE="a
2+
b
3+
c"

tests/multiline-string.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"env": {
3+
"MULTILINE": "a\nb\nc"
4+
},
5+
"shellvars": { }
6+
}

tests/multiline-string.setup.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unset MULTILINE

0 commit comments

Comments
 (0)