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
@@ -420,8 +421,7 @@ text_format() {
420421 }
421422 notify_message () {
422423 local message=" $1 "
423- # shellcheck disable=SC2059
424- [[ -z " $message " ]] || printf -- " $message \n"
424+ [[ -z " $message " ]] || printf -- " %s\n" " $message "
425425 }
426426
427427 notify_stdout () {
@@ -475,7 +475,7 @@ tap_format() {
475475 }
476476 notify_message () {
477477 local message=" $1 "
478- [[ -z " $message " ]] || printf -- " %b \n" " $message " | " $SED " -u -e ' s/^/# /'
478+ [[ -z " $message " ]] || printf -- " %s \n" " $message " | " $SED " -u -e ' s/^/# /'
479479 }
480480 notify_stdout () {
481481 " $SED " ' s:^:# out> :' | color " $GREEN "
Original file line number Diff line number Diff line change @@ -209,6 +209,30 @@ test_failure_status_printed_after_test_name() {
209209 " $( $BASH_UNIT <( echo ' test_fail_should_print_failure() { false; }' ) ) "
210210}
211211
212+ test_notify_message_handles_percent_signs_as_literal_text () {
213+ # Test that printf in notify_message doesn't interpret % as placeholder
214+ bash_unit_output=$( $BASH_UNIT <( echo ' test_percent() { fail "Expected 100% but got 50%" ; }' ) 2>&1 | " $GREP " " Expected 100% but got 50%" )
215+ assert_equals " Expected 100% but got 50%" " $bash_unit_output "
216+ }
217+
218+ test_notify_message_handles_percent_signs_as_literal_text_tap_format () {
219+ # Test that printf in notify_message doesn't interpret % as placeholder
220+ bash_unit_output=$( $BASH_UNIT -f tap <( echo ' test_percent() { fail "Expected 100% but got 50%" ; }' ) 2>&1 | " $GREP " " Expected 100% but got 50%" )
221+ assert_equals " # Expected 100% but got 50%" " $bash_unit_output "
222+ }
223+
224+ test_notify_message_handles_unicode_escape_sequences_as_literal_text () {
225+ # Test that printf in notify_message doesn't interpret escape sequences
226+ bash_unit_output=$( $BASH_UNIT <( printf ' %s\n' ' test_escape() { fail "Symbol: \u2713\nshould be literal" ; }' ) 2>&1 | " $GREP " ' Symbol:' )
227+ assert_matches ' \\u2713\\nshould' " $bash_unit_output "
228+ }
229+
230+ test_notify_message_handles_unicode_escape_sequences_as_literal_text_tap_format () {
231+ # Test that printf in notify_message doesn't interpret escape sequences
232+ bash_unit_output=$( $BASH_UNIT -f tap <( printf ' %s\n' ' test_escape() { fail "Symbol: \u2713\nshould be literal" ; }' ) 2>&1 | " $GREP " ' Symbol:' )
233+ assert_matches ' \\u2713\\nshould' " $bash_unit_output "
234+ }
235+
212236setup () {
213237 # fake basic unix commands bash_unit relies on so that
214238 # we ensure bash_unit keeps working when people fake
You can’t perform that action at this time.
0 commit comments