Skip to content

fix: normalize uid/gid/perms keys in _stat_for before special handling#99

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-stat-for-uid-gid-normalization
Draft

fix: normalize uid/gid/perms keys in _stat_for before special handling#99
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/fix-stat-for-uid-gid-normalization

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented Apr 28, 2026

What

_stat_for() now normalizes all option keys (lowercase + strip st_ prefix) before processing, ensuring uid, gid, and perms handlers work with all key variants.

Why

stat_as_file(st_uid => 42), stat_as_file(ST_GID => 7), etc. silently dropped values. The uid/gid handlers checked $opts->{uid} directly, but key normalization happened in a separate loop afterward — so st_uid never reached the getpwnam resolution path.

This was a known gap noted in learnings but not yet fixed. Since st_uid and st_gid mirror real stat struct field names, users naturally try them.

How

Moved key validation and normalization to a single upfront pass that builds a %norm hash with canonical keys. All downstream handlers (perms, uid, gid, %name2ix loop) now operate on %norm instead of raw $opts.

Testing

  • Added 5 tests to t/stat-key-normalization.t covering st_uid, ST_UID, st_gid, ST_GID, Perms
  • Full test suite passes (all existing tests unaffected)

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 79 insertions(+), 38 deletions(-)

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

stat_as_*(st_uid => 42) and stat_as_*(ST_GID => 7) silently dropped
the values because the uid/gid handlers checked $opts->{uid} directly,
before the normalization loop that strips the st_ prefix. The perms
handler had the same issue.

Move key normalization and validation to the top of _stat_for so all
handlers operate on canonical lowercase keys. This ensures st_uid,
ST_UID, st_gid, ST_GID, Perms, etc. all route through the correct
handlers (including getpwnam/getgrnam resolution for non-numeric values).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant