Skip to content

Commit

Permalink
Don't sanitize vars at dump when they are marked to keep
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpalabsio committed Feb 15, 2025
1 parent 05d8539 commit 3f9a426
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/dump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ _sherpa_dump_current_env() {

_sherpa_dump_current_env__sanitize() {
# shellcheck disable=SC2002
cat "$SHERPA_ENV_FILENAME" |
sed '/^export [^[:space:]]*=/s/=.*/=/' |
sed '/^[^[:space:]]*=/s/=.*/=/'
cat "$SHERPA_ENV_FILENAME" | while IFS= read -r line; do
# Skip if line ends with "# keep"
if [[ $line =~ [[:space:]]*#[[:space:]]*keep[[:space:]]*$ ]]; then
echo "$line"
continue
fi

echo "$line" |
sed '/^export [^[:space:]]*=/s/=.*/=/' |
sed '/^[^[:space:]]*=/s/=.*/=/'
done
}
22 changes: 22 additions & 0 deletions tests/features/dump_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,25 @@ sherpa dump
actual_env_file=$(cat "$SHERPA_ENV_FILENAME.example")

assert_equal "$actual_env_file" "VAR_1="

# ==============================================================================
# ++++ It doesn't sanitize the exported variables if marked to keep

overwrite_env_file "export VAR_1=\"local var 1\" # keep"

sherpa dump

actual_env_file=$(cat "$SHERPA_ENV_FILENAME.example")

assert_equal "$actual_env_file" "export VAR_1=\"local var 1\" # keep"

# ==============================================================================
# ++++ It doesn't sanitize the non-exported variables if marked to keep

overwrite_env_file "VAR_1=\"local var 1\" # keep"

sherpa dump

actual_env_file=$(cat "$SHERPA_ENV_FILENAME.example")

assert_equal "$actual_env_file" "VAR_1=\"local var 1\" # keep"

0 comments on commit 3f9a426

Please sign in to comment.