Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from chronotc/escape-characters
Browse files Browse the repository at this point in the history
handle quotes and newline in commit messages
  • Loading branch information
chronotc authored Aug 3, 2018
2 parents a327468 + ffb3932 commit 7412ea2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/trigger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ function add_build_commit() {
function add_build_message() {
local build_message=$1
default_message="${BUILDKITE_MESSAGE:-}"
sanitized_build_message=$(sanitize_string "${build_message:-$default_message}")

pipeline_yml+=(" message: \"${build_message:-$default_message}\"")
pipeline_yml+=(" message: \"$sanitized_build_message\"")
}

function add_build_branch() {
Expand Down Expand Up @@ -130,3 +131,9 @@ function add_hooks() {
add_command "$command"
done <<< "$(plugin_read_list HOOKS COMMAND)"
}

function sanitize_string() {
local string=$1
escaped_quotes="${string//\"/\\\"}"
echo "$escaped_quotes"
}
17 changes: 17 additions & 0 deletions tests/trigger.bats
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,20 @@ load '/usr/local/lib/bats/load.bash'
assert_output --partial " - command: echo test"
assert_output --partial " - command: aws s3 ls"
}

@test "Preserves quotes in commit messages" {
export BUILDKITE_MESSAGE="Hello world \"stuff\" \n multiline"
export BUILDKITE_PLUGIN_MONOREPO_DIFF_DIFF="cat $PWD/tests/mocks/diff1"
export BUILDKITE_PLUGIN_MONOREPO_DIFF_WATCH_0_PATH="services/foo"
export BUILDKITE_PLUGIN_MONOREPO_DIFF_WATCH_0_CONFIG_TRIGGER="slug-for-foo"
export DEBUG=true

stub buildkite-agent \
"pipeline upload : echo uploading"

run $PWD/hooks/command

unstub buildkite-agent
assert_success
assert_output --partial ' message: "Hello world \"stuff\" \n multiline"'
}

0 comments on commit 7412ea2

Please sign in to comment.