Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/pages/org/[org].vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const {
setSort,
} = useStructuredFilters({
packages,
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc',
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
})
Comment on lines 58 to 61
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Use parseSortOption (not a direct cast) for query-derived sort.

(normalizeSearchParam(route.query.sort) as SortOption) trusts arbitrary query input. An invalid ?sort= value can enter state and bypass the normal defaulting/parsing behaviour described in the PR objective.

Suggested fix
-import type { FilterChip, SortOption } from '#shared/types/preferences'
+import { parseSortOption, type FilterChip, type SortOption } from '#shared/types/preferences'
@@
-  initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
+  initialSort: parseSortOption(normalizeSearchParam(route.query.sort)),

As per coding guidelines: "Ensure you write strictly type-safe code."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} = useStructuredFilters({
packages,
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'updated-desc',
initialSort: (normalizeSearchParam(route.query.sort) as SortOption) ?? 'downloads-week-desc',
})
} = useStructuredFilters({
packages,
initialSort: parseSortOption(normalizeSearchParam(route.query.sort)),
})


// Pagination state
Expand Down Expand Up @@ -86,7 +86,7 @@ const updateUrl = debounce((updates: { filter?: string; sort?: string }) => {
query: {
...route.query,
q: updates.filter || undefined,
sort: updates.sort && updates.sort !== 'updated-desc' ? updates.sort : undefined,
sort: updates.sort && updates.sort !== 'downloads-week-desc' ? updates.sort : undefined,
},
})
}, 300)
Expand All @@ -112,7 +112,7 @@ const totalWeeklyDownloads = computed(() =>
// Reset state when org changes
watch(orgName, () => {
clearAllFilters()
setSort('updated-desc')
setSort('downloads-week-desc')
currentPage.value = 1
})

Expand Down
Loading