fix: getFileCategory must strip the directory before matching basename entries#588
Open
chuenchen309 wants to merge 1 commit into
Open
fix: getFileCategory must strip the directory before matching basename entries#588chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
…e entries
getFileCategory extracted the extension with filePath.split(".").pop() on the full
path, so the two extensionless EXT_MAP entries ("dockerfile", "makefile") never
resolved for real, path-prefixed inputs — every caller passes a full path. A
"/project/Dockerfile" fell through to "unknown", which isBinary() treats as a
non-previewable binary, so Dockerfiles/Makefiles were shown as binary instead of
code. Mirror getFileExtension's dir-strip, then fall back to the basename when it
has no dot.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FdqoGNoq6weGqKvPhm9QRd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
getFileCategoryextracts the extension withfilePath.split(".").pop()on the full path:EXT_MAPhas two extensionless basename entries —dockerfile: "code"andmakefile: "code"— but a path-prefixed file with no.returns the whole path as the "extension", so they never match. Every caller passes a full path (preview.path,selectedFile, …):unknownis inisBinary()'s list, so a Dockerfile/Makefile is treated as a non-previewable binary instead of previewable code.Fix
Mirror the sibling
getFileExtension()(which already strips the directory first), then fall back to the basename itself when it has no dot, so the two basename entries resolve.Test
Added a case to
file-types.test.tscovering bare and path-prefixedDockerfile/Makefile; it fails before the fix and passes after. Existing tests unchanged.Prepared with AI assistance and reviewed before submission.