Skip to content

Commit ac0389e

Browse files
committed
fix: handle spaces and quotes in args
the previous iteration was not properly handling spaces in arguments that users would pass and in the eval that runs the codecov command, those args would get split by their spaces, so now we quote the arguments and we escape whatever quotes they may contain.
1 parent f2fe9b1 commit ac0389e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2424
CODECOV_FAIL_ON_ERROR: true
2525
CODECOV_FLAGS: flag1,flag2
26+
CODECOV_NAME: 'Ubuntu: Test''s "CI & Build" Job'
2627

2728
test-macos:
2829
runs-on: macos-latest
@@ -43,6 +44,7 @@ jobs:
4344
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4445
CODECOV_FAIL_ON_ERROR: true
4546
CODECOV_FLAGS: flag1,flag2
47+
CODECOV_NAME: 'macOS: Test''s "CI & Build" Job'
4648

4749
test-windows:
4850
runs-on: windows-latest
@@ -66,6 +68,7 @@ jobs:
6668
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6769
CODECOV_FAIL_ON_ERROR: true
6870
CODECOV_FLAGS: flag1,flag2
71+
CODECOV_NAME: 'Windows: Test''s "CI & Build" Job'
6972

7073
test-alpine:
7174
runs-on: ubuntu-latest
@@ -86,6 +89,7 @@ jobs:
8689
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8790
CODECOV_FAIL_ON_ERROR: true
8891
CODECOV_FLAGS: flag1,flag2
92+
CODECOV_NAME: 'Alpine: Test''s "CI & Build" Job'
8993

9094
shellcheck:
9195
runs-on: ubuntu-latest

dist/codecov.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ write_bool_args() {
3232
echo "-$(lower $1)"
3333
fi
3434
}
35-
add_cli_arg() { [ -n "$1" ] && CODECOV_CLI_ARGS="${CODECOV_CLI_ARGS:+$CODECOV_CLI_ARGS }$1"; }
36-
add_arg() { [ -n "$1" ] && CODECOV_ARGS="${CODECOV_ARGS:+$CODECOV_ARGS }$1"; }
35+
quote_arg() {
36+
escaped=$(printf '%s\n' "$1" | sed "s/'/'\\\\''/g")
37+
printf "'%s'" "$escaped"
38+
}
39+
add_cli_arg() { [ -n "$1" ] && CODECOV_CLI_ARGS="${CODECOV_CLI_ARGS:+$CODECOV_CLI_ARGS }$(quote_arg "$1")"; }
40+
add_arg() { [ -n "$1" ] && CODECOV_ARGS="${CODECOV_ARGS:+$CODECOV_ARGS }$(quote_arg "$1")"; }
3741
b="\033[0;36m" # variables/constants
3842
g="\033[0;32m" # info/debug
3943
r="\033[0;31m" # errors

scripts/set_funcs.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ write_bool_args() {
3939
fi
4040
}
4141

42-
add_cli_arg() { [ -n "$1" ] && CODECOV_CLI_ARGS="${CODECOV_CLI_ARGS:+$CODECOV_CLI_ARGS }$1"; }
43-
add_arg() { [ -n "$1" ] && CODECOV_ARGS="${CODECOV_ARGS:+$CODECOV_ARGS }$1"; }
42+
quote_arg() {
43+
escaped=$(printf '%s\n' "$1" | sed "s/'/'\\\\''/g")
44+
printf "'%s'" "$escaped"
45+
}
46+
add_cli_arg() { [ -n "$1" ] && CODECOV_CLI_ARGS="${CODECOV_CLI_ARGS:+$CODECOV_CLI_ARGS }$(quote_arg "$1")"; }
47+
add_arg() { [ -n "$1" ] && CODECOV_ARGS="${CODECOV_ARGS:+$CODECOV_ARGS }$(quote_arg "$1")"; }
4448

4549
b="\033[0;36m" # variables/constants
4650
g="\033[0;32m" # info/debug

0 commit comments

Comments
 (0)