Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit d156807

Browse files
secure all .toLowerCase() calls (after a crash report) (#1235)
1 parent 0c1203f commit d156807

17 files changed

Lines changed: 53 additions & 48 deletions

File tree

client/src/CommandBar/steps/AddToStudio.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ const AddToStudio = (props: Props) => {
156156
const newSectionsToShow: CommandBarSectionType[] = [];
157157
initialSections.forEach((s) => {
158158
const items = (s.items as CommandBarItemGeneralType[]).filter((item) => {
159-
return item.label.toLowerCase().includes(inputValue.toLowerCase());
159+
return item.label?.toLowerCase().includes(inputValue?.toLowerCase());
160160
});
161161

162162
if (items.length) {

client/src/CommandBar/steps/Documentation/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ const Documentation = ({}: Props) => {
177177
}
178178
const newSections: CommandBarSectionType[] = [];
179179
sections.forEach((s) => {
180-
const newItems = s.items.filter((i) =>
181-
('label' in i ? i.label : i.componentProps.doc.name)
182-
.toLowerCase()
183-
.includes(inputValue.toLowerCase()),
180+
const newItems = s.items.filter(
181+
(i) =>
182+
('label' in i ? i.label : i.componentProps.doc.name)
183+
?.toLowerCase()
184+
.includes(inputValue?.toLowerCase()),
184185
);
185186
if (newItems.length) {
186187
newSections.push({ ...s, items: newItems });

client/src/CommandBar/steps/Initial.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ const InitialCommandBar = ({ shouldShowTutorial }: Props) => {
434434
}
435435
const newSections: CommandBarSectionType[] = [];
436436
initialSections.forEach((s) => {
437-
const newItems = (s.items as CommandBarItemGeneralType[]).filter((i) =>
438-
i.label.toLowerCase().includes(inputValue.toLowerCase()),
437+
const newItems = (s.items as CommandBarItemGeneralType[]).filter(
438+
(i) => i.label?.toLowerCase().includes(inputValue?.toLowerCase()),
439439
);
440440
if (newItems.length) {
441441
newSections.push({

client/src/CommandBar/steps/LocalRepos.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ const LocalRepos = ({}: Props) => {
140140
}
141141
const newSections: CommandBarSectionType[] = [];
142142
sections.forEach((s) => {
143-
const newItems = s.items.filter((i) =>
144-
('label' in i ? i.label : i.componentProps.repo.shortName)
145-
.toLowerCase()
146-
.includes(inputValue.toLowerCase()),
143+
const newItems = s.items.filter(
144+
(i) =>
145+
('label' in i ? i.label : i.componentProps.repo.shortName)
146+
?.toLowerCase()
147+
.includes(inputValue?.toLowerCase()),
147148
);
148149
if (newItems.length) {
149150
newSections.push({ ...s, items: newItems });

client/src/CommandBar/steps/ManageRepos/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ const ManageRepos = ({ shouldShowTutorial }: Props) => {
172172
) => {
173173
return 'componentProps' in item
174174
? item.componentProps.repo.shortName
175-
.toLowerCase()
176-
.includes(inputValue.toLowerCase())
177-
: item.label.toLowerCase().includes(inputValue.toLowerCase());
175+
?.toLowerCase()
176+
.includes(inputValue?.toLowerCase())
177+
: item.label?.toLowerCase().includes(inputValue?.toLowerCase());
178178
};
179179

180180
sections.forEach((s) => {

client/src/CommandBar/steps/PrivateRepos/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ const PrivateReposStep = ({ shouldShowTutorial }: Props) => {
9191
sections.forEach((s) => {
9292
const items = (s.items as CommandBarItemCustomType[]).filter((item) => {
9393
return item.componentProps.repo.shortName
94-
.toLowerCase()
95-
.includes(inputValue.toLowerCase());
94+
?.toLowerCase()
95+
.includes(inputValue?.toLowerCase());
9696
});
9797

9898
if (items.length) {

client/src/Project/CurrentTabContent/ChatTab/Input/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const ConversationInput = ({
178178
.filter(
179179
(t): t is FileTabType =>
180180
t.type === TabTypesEnum.FILE &&
181-
(!search || t.path.toLowerCase().includes(search.toLowerCase())),
181+
(!search || t.path?.toLowerCase().includes(search?.toLowerCase())),
182182
)
183183
.map((t) => ({ path: t.path, repo: t.repoRef }));
184184
filesResults.push(

client/src/Project/CurrentTabContent/StudioTab/Conversation/Input/TemplatesDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ const TemplatesDropdown = ({ templates, onTemplateSelected }: Props) => {
3939
setTemplatesToShow(templates);
4040
} else {
4141
setTemplatesToShow(
42-
templates.filter((t) =>
43-
t.name.toLowerCase().includes(inputValue.toLowerCase()),
42+
templates.filter(
43+
(t) => t.name?.toLowerCase().includes(inputValue?.toLowerCase()),
4444
),
4545
);
4646
}

client/src/Project/LeftSidebar/NavPanel/Repo/RepoDropdown.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,35 +113,38 @@ const RepoDropdown = ({
113113
if (!search) {
114114
return indexedBranches;
115115
}
116-
return indexedBranches.filter((b) =>
117-
b
118-
.replace(/^origin\//, '')
119-
.toLowerCase()
120-
.includes(search.toLowerCase()),
116+
return indexedBranches.filter(
117+
(b) =>
118+
b
119+
.replace(/^origin\//, '')
120+
?.toLowerCase()
121+
.includes(search?.toLowerCase()),
121122
);
122123
}, [indexedBranches, search]);
123124

124125
const indexingBranchesToShow = useMemo(() => {
125126
if (!search) {
126127
return branchesToSync;
127128
}
128-
return branchesToSync.filter((b) =>
129-
b
130-
.replace(/^origin\//, '')
131-
.toLowerCase()
132-
.includes(search.toLowerCase()),
129+
return branchesToSync.filter(
130+
(b) =>
131+
b
132+
.replace(/^origin\//, '')
133+
?.toLowerCase()
134+
.includes(search?.toLowerCase()),
133135
);
134136
}, [branchesToSync, search]);
135137

136138
const notIndexedBranchesToShow = useMemo(() => {
137139
if (!search) {
138140
return notSyncedBranches;
139141
}
140-
return notSyncedBranches.filter((b) =>
141-
b
142-
.replace(/^origin\//, '')
143-
.toLowerCase()
144-
.includes(search.toLowerCase()),
142+
return notSyncedBranches.filter(
143+
(b) =>
144+
b
145+
.replace(/^origin\//, '')
146+
?.toLowerCase()
147+
.includes(search?.toLowerCase()),
145148
);
146149
}, [notSyncedBranches, search]);
147150

client/src/Project/LeftSidebar/NavPanel/Repo/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const RepoNav = ({
7272
}
7373
return resp?.entries.sort((a, b) => {
7474
if ((a.entry_data === 'Directory') === (b.entry_data === 'Directory')) {
75-
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
75+
return a.name?.toLowerCase() < b.name?.toLowerCase() ? -1 : 1;
7676
} else {
7777
return a.entry_data === 'Directory' ? -1 : 1;
7878
}

0 commit comments

Comments
 (0)