File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717# https://github.com/bash-unit/bash_unit
1818
1919# shellcheck disable=2317 # Ignore unreachable - most function are not called.
20+ # shellcheck disable=2329 # Ignore unreachable - most function are not called.
2021# shellcheck disable=2155 # Ignore Declare and assign separately
2122# spellchecker: ignore NOCOLOR SHUF
2223
@@ -413,8 +414,7 @@ text_format() {
413414 }
414415 notify_message () {
415416 local message=" $1 "
416- # shellcheck disable=SC2059
417- [[ -z " $message " ]] || printf -- " $message \n"
417+ [[ -z " $message " ]] || printf -- " %s\n" " $message "
418418 }
419419
420420 notify_stdout () {
@@ -468,7 +468,7 @@ tap_format() {
468468 }
469469 notify_message () {
470470 local message=" $1 "
471- [[ -z " $message " ]] || printf -- " %b \n" " $message " | " $SED " -u -e ' s/^/# /'
471+ [[ -z " $message " ]] || printf -- " %s \n" " $message " | " $SED " -u -e ' s/^/# /'
472472 }
473473 notify_stdout () {
474474 " $SED " ' s:^:# out> :' | color " $GREEN "
Original file line number Diff line number Diff line change @@ -204,6 +204,30 @@ test_one_test_should_stop_when_assert_fails() {
204204 " $( $BASH_UNIT <( echo ' test_fail() { echo "before failure" >&2 ; assert false ; echo "after failure" >&2 ; }' ) 2>&1 > /dev/null) "
205205}
206206
207+ test_notify_message_handles_percent_signs_as_literal_text () {
208+ # Test that printf in notify_message doesn't interpret % as placeholder
209+ bash_unit_output=$( $BASH_UNIT <( echo ' test_percent() { fail "Expected 100% but got 50%" ; }' ) 2>&1 | " $GREP " " Expected 100% but got 50%" )
210+ assert_equals " Expected 100% but got 50%" " $bash_unit_output "
211+ }
212+
213+ test_notify_message_handles_percent_signs_as_literal_text_tap_format () {
214+ # Test that printf in notify_message doesn't interpret % as placeholder
215+ bash_unit_output=$( $BASH_UNIT -f tap <( echo ' test_percent() { fail "Expected 100% but got 50%" ; }' ) 2>&1 | " $GREP " " Expected 100% but got 50%" )
216+ assert_equals " # Expected 100% but got 50%" " $bash_unit_output "
217+ }
218+
219+ test_notify_message_handles_unicode_escape_sequences_as_literal_text () {
220+ # Test that printf in notify_message doesn't interpret escape sequences
221+ bash_unit_output=$( $BASH_UNIT <( printf ' %s\n' ' test_escape() { fail "Symbol: \u2713\nshould be literal" ; }' ) 2>&1 | " $GREP " ' Symbol:' )
222+ assert_matches ' \\u2713\\nshould' " $bash_unit_output "
223+ }
224+
225+ test_notify_message_handles_unicode_escape_sequences_as_literal_text_tap_format () {
226+ # Test that printf in notify_message doesn't interpret escape sequences
227+ bash_unit_output=$( $BASH_UNIT -f tap <( printf ' %s\n' ' test_escape() { fail "Symbol: \u2713\nshould be literal" ; }' ) 2>&1 | " $GREP " ' Symbol:' )
228+ assert_matches ' \\u2713\\nshould' " $bash_unit_output "
229+ }
230+
207231setup () {
208232 # fake basic unix commands bash_unit relies on so that
209233 # we ensure bash_unit keeps working when people fake
You can’t perform that action at this time.
0 commit comments