Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions functions/csv/parser.awk
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ function output_table (array, m, n, ofs, i, j) {
#?
function output_variable (array, m, n, prefix, quote, single, i, j, fn, fns, fv) {
i = 1
# Pre-type `fns` as an array. Under gawk the first reference `length(fns)` in
# `fns[length(fns)+1]` below otherwise types it as a scalar, then the subscript
# fails with "attempt to use scalar as an array" (BSD awk on macOS tolerates
# it). This empties the parse on Linux — see xsh-lib/xsql query failures.
split("", fns)
for (j=1;j<=n;j++) {
fv = array[i "," j]
fn = get_var_name(fv)
Expand Down
12 changes: 12 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ xsh log info "/json/parser"
xsh log info "/uri/parser"
[[ $(xsh /uri/parser -s https://github.com) == https ]]

# /csv/parser -e exercises output_variable(), which builds `fns[length(fns)+1]`.
# Under gawk (Linux) that typed `fns` as a scalar and emptied the parse; this
# asserts the variable output is populated on every shell/OS.
xsh log info "/csv/parser (-e variable output)"
__csv_tmp=$(mktemp "${TMPDIR:-/tmp}/xsh-csv-test.XXXXXXXX")
printf 'name,age\nalice,30\nbob,25\n' > "$__csv_tmp"
__csv_out=$(xsh /csv/parser -e "$__csv_tmp")
rm -f "$__csv_tmp"
[[ $__csv_out == *"FIELDS_name_ROWS"* ]]
[[ $__csv_out == *alice* ]]
[[ $__csv_out == *bob* ]]

# ---------- dotfile ----------
# Tests use a temporary repo with a .dotfilemap to avoid depending on any
# real dotfile repository.
Expand Down