From f7732101e8e495dbd3d6bfb64c3e3c3fb67a5314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E7=A7=8B=E6=9E=AB=E5=BD=B1?= Date: Thu, 17 Mar 2022 12:01:33 +0800 Subject: [PATCH] fix search index out of bounds error (#548) Co-authored-by: spencerwooo --- components/SearchModal.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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('/') + : '' } /**