diff --git a/components/SearchModal.tsx b/components/SearchModal.tsx index 7393257..6061c12 100644 --- a/components/SearchModal.tsx +++ b/components/SearchModal.tsx @@ -27,13 +27,15 @@ import siteConfig from '../config/site.config' function mapAbsolutePath(path: string): string { // path is in the format of '/drive/root:/path/to/file', if baseDirectory is '/' then we split on 'root:', // otherwise we split on the user defined 'baseDirectory' - const absolutePath = path.split(siteConfig.baseDirectory === '/' ? 'root:' : siteConfig.baseDirectory)[1] + const absolutePath = path.split(siteConfig.baseDirectory === '/' ? 'root:' : siteConfig.baseDirectory) // path returned by the API may contain #, by doing a decodeURIComponent and then encodeURIComponent we can // replace URL sensitive characters such as the # with %23 - return absolutePath - .split('/') - .map(p => encodeURIComponent(decodeURIComponent(p))) - .join('/') + return absolutePath.length > 1 // solve https://github.com/spencerwooo/onedrive-vercel-index/issues/539 + ? absolutePath[1] + .split('/') + .map(p => encodeURIComponent(decodeURIComponent(p))) + .join('/') + : '' } /**