[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: handle trailing slashes on catchall paths (#673)

authored by

Alex Savelyev and committed by
GitHub
7071ba51 d7145915

+17 -7
+1 -1
app/composables/usePackageRoute.ts
··· 13 13 const route = useRoute('package') 14 14 15 15 const parsedRoute = computed(() => { 16 - const segments = route.params.package || [] 16 + const segments = route.params.package?.filter(Boolean) || [] 17 17 18 18 // Find the /v/ separator for version 19 19 const vIndex = segments.indexOf('v')
+15 -5
app/pages/code/[...path].vue
··· 42 42 43 43 const packageName = computed(() => parsedRoute.value.packageName) 44 44 const version = computed(() => parsedRoute.value.version) 45 - const filePath = computed(() => parsedRoute.value.filePath) 45 + const filePathOrig = computed(() => parsedRoute.value.filePath) 46 + const filePath = computed(() => parsedRoute.value.filePath?.replace(/\/$/, '')) 46 47 47 48 // Fetch package data for version list 48 49 const { data: pkg } = usePackage(packageName) ··· 64 65 // Determine what to show based on the current path 65 66 // Note: This needs fileTree to be loaded first 66 67 const currentNode = computed(() => { 67 - if (!fileTree.value?.tree || !filePath.value) return null 68 + if (!fileTree.value?.tree || !filePathOrig.value) return null 68 69 69 - const parts = filePath.value.split('/') 70 + // We use original file path to correctly handle trailing slashes for file tree navigation 71 + // - /src/index.ts - correct file path 72 + // - /src/index.ts/ - incorrect file path (but formally can exist as a directory) 73 + // - /src/index and /src/index/ - correct directory paths 74 + const parts = filePathOrig.value.split('/') 70 75 let current: PackageFileTree[] | undefined = fileTree.value.tree 71 76 let lastFound: PackageFileTree | null = null 77 + const partsLength = parts.length 72 78 73 - for (const part of parts) { 79 + for (let i = 0; i < partsLength; i++) { 80 + const part = parts[i] 81 + const isLast = i === partsLength - 1 82 + // If the previous part is a directory and the last one is empty (like /lib/) then return the previous directory 83 + if (!part && isLast && lastFound?.type === 'directory') return lastFound 74 84 const found: PackageFileTree | undefined = current?.find(n => n.name === part) 75 85 if (!found) return null 76 86 lastFound = found 77 - if (found.type === 'file') return found 87 + if (found.type === 'file' && isLast) return found 78 88 current = found.children 79 89 } 80 90
+1 -1
app/pages/docs/[...path].vue
··· 11 11 const router = useRouter() 12 12 13 13 const parsedRoute = computed(() => { 14 - const segments = route.params.path || [] 14 + const segments = route.params.path?.filter(Boolean) || [] 15 15 const vIndex = segments.indexOf('v') 16 16 17 17 if (vIndex === -1 || vIndex >= segments.length - 1) {