Skip to content

Commit 12f8240

Browse files
fix(web): add type guard to prevent crash with 'constructor' folder name (#862)
* fix: add type guard to prevent crash with 'constructor' folder name Fixes #861 When a folder is named 'constructor', getIconForFolder returns an object (Object.prototype.constructor) instead of a string, causing a runtime error when calling .indexOf() on it. Added a type check to ensure the icon is a string before processing. Co-authored-by: Brendan Kellam <brendan-kellam@users.noreply.github.com> * changelog and nits --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Brendan Kellam <brendan-kellam@users.noreply.github.com>
1 parent 0c2fe99 commit 12f8240

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
### Changed
1414
- Improved stability for connection and repo indexing workers. [#860](https://github.com/sourcebot-dev/sourcebot/pull/860)
1515

16+
### Fixed
17+
- Fixed issue where certain file and folder names would cause type errors. [#862](https://github.com/sourcebot-dev/sourcebot/pull/862)
18+
1619
## [4.10.27] - 2026-02-05
1720

1821
### Fixed

packages/web/src/app/components/vscodeFileIcon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ interface VscodeFileIconProps {
1313
export const VscodeFileIcon = ({ fileName, className }: VscodeFileIconProps) => {
1414
const iconName = useMemo(() => {
1515
const icon = getIconForFile(fileName);
16-
if (icon) {
16+
if (icon && typeof icon === 'string') {
1717
const iconName = `vscode-icons:${icon.substring(0, icon.indexOf('.')).replaceAll('_', '-')}`;
1818
return iconName;
1919
}
2020

21-
return "vscode-icons:file-type-unknown";
21+
return "vscode-icons:default-file";
2222
}, [fileName]);
2323

2424
return <Icon icon={iconName} className={cn("w-4 h-4 flex-shrink-0", className)} />;

packages/web/src/app/components/vscodeFolderIcon.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ interface VscodeFolderIconProps {
1313
export const VscodeFolderIcon = ({ folderName, className }: VscodeFolderIconProps) => {
1414
const iconName = useMemo(() => {
1515
const icon = getIconForFolder(folderName);
16-
if (icon) {
16+
if (icon && typeof icon === 'string') {
1717
const iconName = `vscode-icons:${icon.substring(0, icon.indexOf('.')).replaceAll('_', '-')}`;
1818
return iconName;
1919
}
2020

21-
return "vscode-icons:folder";
21+
return "vscode-icons:default-folder";
2222
}, [folderName]);
2323

2424
return <Icon icon={iconName} className={cn("w-4 h-4 flex-shrink-0", className)} />;

0 commit comments

Comments
 (0)