Skip to content
Open
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
7 changes: 6 additions & 1 deletion lib/bash/std/lib_std.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3618,9 +3618,14 @@ __base_bash_libs_std_validate_array_kind__() {
(($# >= 3)) || return 1
local __base_bash_libs_std_validate_array_operation="$1" __base_bash_libs_std_validate_array_kind="$2"
local __base_bash_libs_std_validate_array_name __base_bash_libs_std_validate_array_label=indexed
local -i __base_bash_libs_std_validate_array_kind_code=0
shift 2

[[ "$__base_bash_libs_std_validate_array_kind" == "A" ]] &&
# Compare the marker byte numerically so caller `nocasematch` cannot make
# Bash classify the indexed marker `a` as the associative marker `A`.
printf -v __base_bash_libs_std_validate_array_kind_code '%d' \
"'$__base_bash_libs_std_validate_array_kind"
((__base_bash_libs_std_validate_array_kind_code == 65)) &&
__base_bash_libs_std_validate_array_label=associative
__base_bash_libs_std_validate_variable_names__ \
"$__base_bash_libs_std_validate_array_operation" "$@" || return 1
Expand Down
17 changes: 17 additions & 0 deletions lib/bash/std/tests/lib_std.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4575,6 +4575,23 @@ EOF
shopt -q nocasematch
}

@test "array-kind validation keeps indexed diagnostics case-sensitive with nocasematch" {
local -A associative_values=([alpha]=one)
local stderr_file="$TEST_TMPDIR/array-kind-validation.err"
local status

shopt -s nocasematch
if __base_bash_libs_std_validate_array_kind__ base_std_test a associative_values 2>"$stderr_file"; then
status=0
else
status=$?
fi
shopt -u nocasematch

[ "$status" -eq 1 ]
[[ "$(cat "$stderr_file")" == *"must be a caller-declared indexed array."* ]]
}

@test "base_std_assert_associative_array accepts declared associative arrays" {
local -A values=([alpha]="one")

Expand Down
2 changes: 1 addition & 1 deletion lib/bash/str/tests/lib_str.bats
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ create_script() {

[ "$rc" -eq 2 ]
[ "${fields[keep]}" = sentinel ]
[[ "$(<"$stderr_file")" == *"attributes incompatible with the indexed-array output contract"* ]]
[[ "$(<"$stderr_file")" == *"must be a caller-declared indexed array"* ]]
}

@test "readonly string outputs cannot collide with argument-count decimal locals" {
Expand Down
Loading