Skip to content

Commit 974ccd1

Browse files
Aki Arviopgrange
authored andcommitted
Handle escape sequences in notify_message
- To keep it more proper looking handle escape sequences are before. Just ensure % are not interpreted as placeholders.
1 parent 16ac92e commit 974ccd1

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

bash_unit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ text_format() {
421421
}
422422
notify_message() {
423423
local message="$1"
424-
[[ -z "$message" ]] || printf -- "%s\n" "$message"
424+
[[ -z "$message" ]] || printf -- "%b\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 -- "%s\n" "$message" | "$SED" -u -e 's/^/# /'
478+
[[ -z "$message" ]] || printf -- "%b\n" "$message" | "$SED" -u -e 's/^/# /'
479479
}
480480
notify_stdout() {
481481
"$SED" 's:^:# out> :' | color "$GREEN"

tests/test_cli.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,16 @@ test_notify_message_handles_percent_signs_as_literal_text_tap_format() {
221221
assert_equals "# Expected 100% but got 50%" "$bash_unit_output"
222222
}
223223

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"
224+
test_notify_message_renders_unicode_characters_correctly() {
225+
# Test that notify_message properly interprets Unicode escape sequences and newlines
226+
bash_unit_output=$($BASH_UNIT <(printf '%s\n' 'test_escape() { fail "Symbol: \u2713\nMultiline message" ; }') 2>&1 || : )
227+
assert_matches "Symbol: ✓"$'\n'"Multiline message" "$bash_unit_output"
228228
}
229229

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"
230+
test_notify_message_renders_unicode_characters_correctly_tap_format() {
231+
# Test that notify_message properly interprets Unicode escape sequences and newlines in TAP format
232+
bash_unit_output=$($BASH_UNIT -f tap <(printf '%s\n' 'test_escape() { fail "Symbol: \u2713\nMultiline message" ; }') 2>&1 || : )
233+
assert_matches "# Symbol: ✓"$'\n'"# Multiline message" "$bash_unit_output"
234234
}
235235

236236
setup() {

0 commit comments

Comments
 (0)