Skip to content

Commit af87aeb

Browse files
dschogitster
authored andcommitted
test(junit): avoid line feeds in XML attributes
In the test case's output, we do want newline characters, but in the XML attributes we do not want them. However, the `xml_attr_encode` function always adds a Line Feed at the end (which are then encoded as `&#x0a;`, even for XML attributes. This seems not to faze Azure Pipelines' XML parser, but it still is incorrect, so let's fix it. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6527fbc commit af87aeb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

t/test-lib-junit.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ finalize_test_case_output () {
5050
;;
5151
failure)
5252
junit_insert="<failure message=\"not ok $test_count -"
53-
junit_insert="$junit_insert $(xml_attr_encode "$1")\">"
53+
junit_insert="$junit_insert $(xml_attr_encode --no-lf "$1")\">"
5454
junit_insert="$junit_insert $(xml_attr_encode \
5555
"$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
5656
then
@@ -74,12 +74,12 @@ finalize_test_case_output () {
7474
set "$* (known breakage)"
7575
;;
7676
skip)
77-
message="$(xml_attr_encode "$skipped_reason")"
77+
message="$(xml_attr_encode --no-lf "$skipped_reason")"
7878
set "$1" " <skipped message=\"$message\" />"
7979
;;
8080
esac
8181

82-
junit_attrs="name=\"$(xml_attr_encode "$this_test.$test_count $1")\""
82+
junit_attrs="name=\"$(xml_attr_encode --no-lf "$this_test.$test_count $1")\""
8383
shift
8484
junit_attrs="$junit_attrs classname=\"$this_test\""
8585
junit_attrs="$junit_attrs time=\"$(test-tool \
@@ -122,5 +122,11 @@ write_junit_xml () {
122122
}
123123

124124
xml_attr_encode () {
125-
printf '%s\n' "$@" | test-tool xml-encode
125+
if test "x$1" = "x--no-lf"
126+
then
127+
shift
128+
printf '%s' "$*" | test-tool xml-encode
129+
else
130+
printf '%s\n' "$@" | test-tool xml-encode
131+
fi
126132
}

0 commit comments

Comments
 (0)