Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/freebsd/poudriere.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Drewery <bryan@shatow.net>2022-09-09 23:28:54 +0300
committerBryan Drewery <bryan@shatow.net>2022-11-05 18:47:57 +0300
commit6c12bc766ce8cddbd4f732f0df5592e5c596b0e0 (patch)
tree5d60cf46461d723419e1034b1a7c978dd5a1b469
parenteab6c4c5162f9c45469700002ee638155d315b80 (diff)
display: Fix sorting due to internally quoted values
-rw-r--r--src/share/poudriere/include/display.sh35
-rw-r--r--test/display.sh24
2 files changed, 48 insertions, 11 deletions
diff --git a/src/share/poudriere/include/display.sh b/src/share/poudriere/include/display.sh
index d18cd709..40e64fa8 100644
--- a/src/share/poudriere/include/display.sh
+++ b/src/share/poudriere/include/display.sh
@@ -32,16 +32,23 @@ display_setup() {
}
display_add() {
- local arg
+ local arg line tab
- # Add in newline
- [ -n "${_DISPLAY_DATA}" ] && \
- _DISPLAY_DATA="${_DISPLAY_DATA}
-"
- # Quote all arguments
+ unset line
+ tab=$'\t'
+ # Ensure blank arguments and spaced-arguments are respected.
+ # This is mostly to deal with sorting later
for arg do
- _DISPLAY_DATA="${_DISPLAY_DATA} '${arg}'"
+ if [ -z "${arg}" ]; then
+ arg=" "
+ fi
+ line="${line:+${line}${tab}}${arg}"
done
+ # Add in newline
+ if [ -n "${_DISPLAY_DATA}" ]; then
+ _DISPLAY_DATA="${_DISPLAY_DATA}"$'\n'
+ fi
+ _DISPLAY_DATA="${_DISPLAY_DATA:+${_DISPLAY_DATA}}${line}"
return 0
}
@@ -77,7 +84,9 @@ display_output() {
fi
header="${line}"
fi
- eval "set -- ${line}"
+ IFS=$'\t'
+ set -- ${line}
+ unset IFS
cnt=0
for arg in "$@"; do
hash_get lengths ${cnt} max_length || max_length=0
@@ -123,15 +132,19 @@ display_output() {
if [ "${quiet}" -eq 0 ]; then
stripansi "${header}" header
stripansi "${format}" header_format
- eval "set -- ${header}"
+ IFS=$'\t'
+ set -- ${header}
+ unset IFS
printf "${header_format}\n" "$@"
fi
# Sort as configured in display_setup()
echo "${_DISPLAY_DATA}" | tail -n +2 | \
- sort ${_DISPLAY_COLUMN_SORT} | \
+ sort -t $'\t' ${_DISPLAY_COLUMN_SORT} | \
while mapfile_read_loop_redir line; do
- eval "set -- ${line}"
+ IFS=$'\t'
+ set -- ${line}
+ unset IFS
printf "${format}\n" "$@"
done
diff --git a/test/display.sh b/test/display.sh
index e9a4281c..82d4b671 100644
--- a/test/display.sh
+++ b/test/display.sh
@@ -49,3 +49,27 @@ blah 10.2-RELEASE-p10
blah 11.2-RELEASE-p1
EOF
assert_file "${expected}" "${outfile}"
+
+display_setup "%%%ds %%-%ds %%-%ds" "-k1,1n"
+display_add "JID" "IP Address" "vnet_num"
+display_add "189" "" 0
+display_add "188" "" 0
+display_add "187" "" 0
+display_add "150" "10.2.1.4,127.0.1.4" 0
+display_add "99" "10.2.1.3,127.0.1.3" 0
+display_add "87" "192.168.2.38" 0
+display_add "85" "192.168.2.52" 0
+outfile=$(mktemp -t outfile)
+display_output > "${outfile}"
+expected=$(mktemp -t expected)
+cat > "${expected}" <<-EOF
+JID IP Address vnet_num
+ 85 192.168.2.52 0
+ 87 192.168.2.38 0
+ 99 10.2.1.3,127.0.1.3 0
+150 10.2.1.4,127.0.1.4 0
+187 0
+188 0
+189 0
+EOF
+assert_file "${expected}" "${outfile}"