fix: handle unicode filename and website uploads (#491)

* fix: print meaningful error message for invalid filenames

* fix: handle unicode dirnames and filenames

* chore: revert custom error message
This commit is contained in:
Cafe137
2022-07-26 13:13:25 +02:00
committed by GitHub
parent fd11f0166d
commit f82444f212
9 changed files with 167 additions and 7 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ export function Upload(): ReactElement {
let fls: FilePath[] = files.map(f => packageFile(f)) // Apart from packaging, this is needed to not modify the original files array as it can trigger effects
let indexDocument: string | undefined = undefined // This means we assume it's folder
if (files.length === 1) indexDocument = files[0].name
if (files.length === 1) indexDocument = unescape(encodeURIComponent(files[0].name))
else if (files.length > 1) {
const idx = detectIndexHtml(files)
+15 -4
View File
@@ -18,15 +18,26 @@ export function detectIndexHtml(files: FilePath[]): DetectedIndex | false {
return { indexPath: exactMatch }
}
const prefix = paths[0].split('/')[0] + '/'
const sortedPaths = paths.sort((a, b) => a.localeCompare(b))
const firstSegments = sortedPaths[0].split('/')
const lastSegments = sortedPaths[sortedPaths.length - 1].split('/')
let matchingSegments = 0
const allStartWithSamePrefix = paths.every(x => x.startsWith(prefix))
for (; matchingSegments < firstSegments.length; matchingSegments++) {
if (firstSegments[matchingSegments] !== lastSegments[matchingSegments]) {
break
}
}
const commonPrefix = firstSegments.slice(0, matchingSegments).join('/') + '/'
const allStartWithSamePrefix = paths.every(x => x.startsWith(commonPrefix))
if (allStartWithSamePrefix) {
const match = paths.find(x => indexHtmls.map(y => prefix + y).includes(x))
const match = paths.find(x => indexHtmls.map(y => commonPrefix + y).includes(x))
if (match) {
return { indexPath: match, commonPrefix: prefix }
return { indexPath: match, commonPrefix }
}
}