Skip to content

Commit 8d3c91d

Browse files
committed
fix: fix null check logic in getFilenameFromResponse
1 parent ee314bb commit 8d3c91d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/utils/fetchUtilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ export const getFilenameFromResponse = (response: Response): string => {
206206
const contentDisposition = response.headers.get('Content-Disposition')
207207
// Try to extract UTF-8 filename first
208208
const utf8Filename = contentDisposition?.match(/filename\*=utf-8'.*'(.*?)(?:;|$)/i)
209-
if (utf8Filename?.[1] !== '') {
210-
return decodeURIComponent(utf8Filename![1])
209+
if (utf8Filename?.[1] && utf8Filename[1].length > 0) {
210+
return decodeURIComponent(utf8Filename[1])
211211
}
212212
// Fallback to regular filename
213213
const filename = contentDisposition?.match(/filename="?(.*?)(?:"|;|$)/i)
214-
if (filename?.[1] !== '') {
215-
return filename![1]
214+
if (filename?.[1] && filename[1].length > 0) {
215+
return filename[1]
216216
}
217217
// Fallback to URL path
218218
const url = new URL(response.url)

0 commit comments

Comments
 (0)