Speed up downloads by combining multiple network connections in parallel
TypeScript bandwidth-aggregationcross-platformdesktop-appdownloaderdownloadmanagerlinuxmacosmulticonnectionparallel-downloadswindows
fix: refuse torrent files that differ only by Unicode normalization (#179)
Rudy Mizrahi Celekli022ef292a300
diff --git a/e2e/torrentPaths.spec.ts b/e2e/torrentPaths.spec.tsindex 1248f06..0f8c2a2 100644--- a/e2e/torrentPaths.spec.ts+++ b/e2e/torrentPaths.spec.ts@@ -72,6 +72,9 @@ test.describe('torrent paths', () => {refused(['../evil'])refused(['Name/../../evil'])refused(['Name/A.txt', 'Name/a.txt'])+ // é composed and decomposed: macOS saves both under one name.+ refused(['Name/caf\u00e9.txt', 'Name/cafe\u0301.txt'])+ refused(['Caf\u00e9/a.txt', 'Cafe\u0301/a.txt'])refused(['Name/x', 'Name/x/y'])refused(['Name/::'])refused(['Name/CON.txt'], 'win32')diff --git a/src/main/download/torrent/paths.ts b/src/main/download/torrent/paths.tsindex c30d2a4..7712668 100644--- a/src/main/download/torrent/paths.ts+++ b/src/main/download/torrent/paths.ts@@ -50,14 +50,16 @@ export function safeTorrentPaths(return { path: relative, length: file.length }})- // Compared without case: macOS and Windows treat "A.txt" and "a.txt" as one file. A file can't- // also be a folder another file sits in.- const taken = new Set(checked.map((file) => file.path.toLowerCase()))+ // Compared without case: macOS and Windows treat "A.txt" and "a.txt" as one file, and macOS+ // treats an é composed or decomposed as one too. A file can't also be a folder another file+ // sits in.+ const key = (file: { path: string }): string => file.path.normalize('NFC').toLowerCase()+ const taken = new Set(checked.map(key))if (taken.size !== checked.length) {throw new UnsafeTorrentError('Two files in this torrent would be saved as the same file')}for (const file of checked) {- const segments = file.path.toLowerCase().split(path.sep)+ const segments = key(file).split(path.sep)for (let end = 1; end < segments.length; end++) {if (taken.has(segments.slice(0, end).join(path.sep))) {throw new UnsafeTorrentError('A file in this torrent has the same name as a folder in it')