diff options
| -rwxr-xr-x | bin/shuriken | 12 | ||||
| -rw-r--r-- | src/lib/stats-aggregate.source.sh | 12 | ||||
| -rwxr-xr-x | tests/cli.sh | 8 |
3 files changed, 28 insertions, 4 deletions
diff --git a/bin/shuriken b/bin/shuriken index 0b1afa2..a753b9a 100755 --- a/bin/shuriken +++ b/bin/shuriken @@ -5046,11 +5046,19 @@ stats_category_size() { stats_category_max() { local -n _stats_counts_ref="$1"; shift local key + local -i value local -i max=0 for key in "${!_stats_counts_ref[@]}"; do - if (( _stats_counts_ref[key] > max )); then - max=${_stats_counts_ref[$key]} + # Read the value through a quoted ${assoc[$key]} expansion FIRST, then + # compare. Do NOT write "(( _stats_counts_ref[key] > max ))": inside an + # arithmetic context an associative subscript is itself arithmetic- + # evaluated, so a string key (e.g. "sony") resolves to an unset var -> 0, + # i.e. it would always read index 0 and report max 0 (broken zero-width + # bars). The string-keyed expansion below is the only correct read. + value=${_stats_counts_ref[$key]} + if (( value > max )); then + max=$value fi done printf '%d' "$max" diff --git a/src/lib/stats-aggregate.source.sh b/src/lib/stats-aggregate.source.sh index 3c013b3..ff06d15 100644 --- a/src/lib/stats-aggregate.source.sh +++ b/src/lib/stats-aggregate.source.sh @@ -772,11 +772,19 @@ stats_category_size() { stats_category_max() { local -n _stats_counts_ref="$1"; shift local key + local -i value local -i max=0 for key in "${!_stats_counts_ref[@]}"; do - if (( _stats_counts_ref[key] > max )); then - max=${_stats_counts_ref[$key]} + # Read the value through a quoted ${assoc[$key]} expansion FIRST, then + # compare. Do NOT write "(( _stats_counts_ref[key] > max ))": inside an + # arithmetic context an associative subscript is itself arithmetic- + # evaluated, so a string key (e.g. "sony") resolves to an unset var -> 0, + # i.e. it would always read index 0 and report max 0 (broken zero-width + # bars). The string-keyed expansion below is the only correct read. + value=${_stats_counts_ref[$key]} + if (( value > max )); then + max=$value fi done printf '%d' "$max" diff --git a/tests/cli.sh b/tests/cli.sh index ca5d170..cc0bd1c 100755 --- a/tests/cli.sh +++ b/tests/cli.sh @@ -4799,6 +4799,14 @@ BASH test::assert_contains \ '<a href="camera-canon-eos-5d/index.html">Canon EOS 5D</a>' "$html" test::assert_contains '2 (67%)' "$html" + # Gauge bars scale each bucket to its section's busiest bucket: with 2 Canon + # vs 1 Nikon the camera bars are 100% and 50% wide. Regression guard: a prior + # stats_category_max bug (arithmetic subscript on an associative-array nameref + # resolving the string key to 0) returned max 0, collapsing EVERY bar to + # width:0%. Asserting the non-zero widths catches that; the byte-identical + # double-render test could not (both renders were equally broken). + test::assert_contains 'class="stats-bar-fill" style="width:100%"' "$html" + test::assert_contains 'class="stats-bar-fill" style="width:50%"' "$html" # A histogram section is present. test::assert_contains '<h2>ISO</h2>' "$html" test::assert_contains '400' "$html" |
