Skip to content

Commit 33ae886

Browse files
Merge pull request bats-core#1176 from martin-schulze-vireso/fix/junit-control-characters
fix(junit-formatter): remove control characters
2 parents afd1643 + d5f3f4e commit 33ae886

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
1313

1414
### Fixed
1515

16-
* avoid interference from env to junit formatter internals (#1175)
16+
* junit formatter:
17+
* avoid interference between env and internals (#1175)
18+
* remove control characters (\x00-\x08\x0B\x0C\x0E-\x1F) (#1176)
1719

1820
## [1.13.0] - 2025-11-07
1921

libexec/bats-core/bats-format-junit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,6 @@ main() {
282282
finish_suite # ensure we run this with the local variables still in scope
283283
}
284284

285-
main "$@"
285+
# [\x00-\x08\x0B\x0C\x0E-\x1F] can't use $'\x00' as this terminates the string early
286+
BATS_JUNIT_FORMATTER_DELETE_CHARS_DEFAULT='\000'$'\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F'
287+
main "$@" | tr -d "${BATS_JUNIT_FORMATTER_DELETE_CHARS-$BATS_JUNIT_FORMATTER_DELETE_CHARS_DEFAULT}"

test/fixtures/junit-formatter/xml-escape.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
}
44

55
@test "Failed test with escape characters: \"'<>& (0x1b)" {
6-
echo "<>'&[0m[K" && false
6+
echo "<>'&[0m[K"$'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1fstop' && false
77
}
88

99
@test "Skipped test with escape characters: \"'<>& (0x1b)" {

test/junit-formatter.bats

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"
5656
[[ "${lines[3]}" == " <testcase classname=\"$ESCAPED_TEST_FILE_NAME\" name=\"Successful test with escape characters: &quot;&#39;&lt;&gt;&amp; (0x1b)\" time=\""*"\" />" ]]
5757
[[ "${lines[4]}" == " <testcase classname=\"$ESCAPED_TEST_FILE_NAME\" name=\"Failed test with escape characters: &quot;&#39;&lt;&gt;&amp; (0x1b)\" "* ]]
5858
[[ "${lines[5]}" == ' <failure type="failure">(in test file '*"$ESCAPED_TEST_FILE_NAME, line 6)" ]]
59-
[[ "${lines[6]}" == ' `echo &quot;&lt;&gt;&#39;&amp;&quot; &amp;&amp; false&#39; failed'* ]]
60-
[[ "${lines[9]}" == " <testcase classname=\"$ESCAPED_TEST_FILE_NAME\" name=\"Skipped test with escape characters: &quot;&#39;&lt;&gt;&amp; (0x1b)\" time=\""*"\">" ]]
61-
[[ "${lines[10]}" == " <skipped>&quot;&#39;&lt;&gt;&amp;</skipped>" ]]
59+
[[ "${lines[6]}" == ' `echo &quot;&lt;&gt;&#39;&amp;&quot;$&#39;\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1fstop&#39; &amp;&amp; false&#39; failed'* ]]
60+
[[ "${lines[7]}" == '&lt;&gt;&#39;&amp;' ]]
61+
[[ "${lines[8]}" == $'\x0Dstop</failure>' ]]
62+
[[ "${lines[10]}" == " <testcase classname=\"$ESCAPED_TEST_FILE_NAME\" name=\"Skipped test with escape characters: &quot;&#39;&lt;&gt;&amp; (0x1b)\" time=\""*"\">" ]]
63+
[[ "${lines[11]}" == " <skipped>&quot;&#39;&lt;&gt;&amp;</skipped>" ]]
6264
}
6365

6466
@test "junit formatter: test suites" {

0 commit comments

Comments
 (0)