Skip to content

Commit d312f3f

Browse files
author
Aki Arvio
committed
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 f58c78e commit d312f3f

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

bash_unit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ text_format() {
414414
}
415415
notify_message() {
416416
local message="$1"
417-
[[ -z "$message" ]] || printf -- "%s\n" "$message"
417+
[[ -z "$message" ]] || printf -- "%b\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 -- "%s\n" "$message" | "$SED" -u -e 's/^/# /'
471+
[[ -z "$message" ]] || printf -- "%b\n" "$message" | "$SED" -u -e 's/^/# /'
472472
}
473473
notify_stdout() {
474474
"$SED" 's:^:# out> :' | color "$GREEN"

tests/test_cli.sh

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

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

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

231231
setup() {

0 commit comments

Comments
 (0)