Improve ZIP subtype detection and naming#69
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
PR Review: Improve ZIP subtype detection and namingOverall this is a clean, well-motivated change. The problem being solved is real, the implementation is mostly sound, and the tests are a good start. A few things worth addressing before merge: Bug / Logic concern
The original code had an early-return guard immediately after populating if (detected == null || string.IsNullOrEmpty(decl))
return cmp;The new code inserts the guessOnly block before that guard, so the guard is now further down. This is safe at runtime because the new block's own null-checks ( if (detected == null || string.IsNullOrEmpty(decl))
return cmp;
// New guessOnly block here — detected is guaranteed non-null
if (!string.IsNullOrEmpty(detGuess) && ...)
{ ... }Test gap
The PR description calls out Test assertion oddityIn the same test: Assert.Equal("zip", res!.Extension); // base type stays "zip"
Assert.Equal("apk", res.GuessedExtension); // subtype in GuessedExtension
Assert.Equal("application/vnd.android.package-archive", res.MimeType); // subtype MIMEThe MimeType is now the subtype MIME while Minor: duplicate
|
PR Review: Improve ZIP subtype detection and namingGood improvement overall — the detection pipeline for ZIP-derived formats is meaningfully more precise, and the added tests cover the key cases. A few things worth addressing: Bug / Potential Regression
The Dead Code
if (!string.IsNullOrEmpty(detGuess) &&
!Equivalent(decl, det) &&
Equivalent(decl, detGuess!))
{
det = detGuess!;
detLabel = detGuess! + " (guess)"; // ← never used
}After this block, Redundant Null CheckIn if (!string.IsNullOrEmpty(decl) && // ← redundant
!string.IsNullOrEmpty(detGuess) &&
...)There's already an early return Missing Test CoverageIPA subtype MIME fallback is untested. Also, Minor NitInconsistent brace style in test file. The new tests use Allman style while the surrounding existing tests use K&R/inline style. The reformatting of Summary
The core logic — promoting |
What changed
apk,jar,epub, and related formats are recognized as their real type instead of collapsing to generic ZIPWhy
ZIP-derived container formats were still easy to flatten back to
zip, which made reporting less precise and could cause declared-type mismatch noise.Impact
FileInspectorX now returns more accurate type labels for ZIP-derived formats, which gives downstream systems cleaner detection, comparison, and reporting data.
Validation
dotnet test FileInspectorX.Tests\\FileInspectorX.Tests.csproj