Use PathMapper.normalizePath for relocation checks

Make path-boundary checks separator-agnostic by exposing and enhancing PathMapper.normalizePath and using it in processMonitorDownload. normalizePath now converts backslashes to forward slashes, collapses redundant separators and `..` segments, and strips trailing separators (except root). The relocation test in processMonitorDownload now compares normalized download/save paths and treats a path as "relocated" only when equal-to or a child of the save path (boundary enforced). Added unit and integration tests to cover Windows backslashes, trailing separators, `..` collapse, sibling-prefix edge cases, and preserved existing wait/retry behavior (#209).
This commit is contained in:
kikootwo
2026-05-27 02:38:34 -04:00
parent 97d5aeb651
commit 47c5f34fb9
4 changed files with 249 additions and 8 deletions
+21
View File
@@ -46,6 +46,27 @@ describe('PathMapper', () => {
).toThrow('Local path cannot be empty');
});
describe('normalizePath', () => {
it('converts backslashes to forward slashes (Windows clients)', () => {
expect(PathMapper.normalizePath('E:\\Torrents\\ReadMeABook\\Book.m4b'))
.toBe('E:/Torrents/ReadMeABook/Book.m4b');
});
it('normalizes mixed separators consistently', () => {
expect(PathMapper.normalizePath('E:\\Torrents/ReadMeABook\\Book'))
.toBe('E:/Torrents/ReadMeABook/Book');
});
it('strips trailing separators (both forms)', () => {
expect(PathMapper.normalizePath('E:\\Torrents\\ReadMeABook\\')).toBe('E:/Torrents/ReadMeABook');
expect(PathMapper.normalizePath('/downloads/readmeabook/')).toBe('/downloads/readmeabook');
});
it('collapses `..` segments and redundant separators', () => {
expect(PathMapper.normalizePath('/downloads//readmeabook/../Book')).toBe('/downloads/Book');
});
});
describe('reverseTransform', () => {
it('returns original path when mapping is disabled', () => {
const result = PathMapper.reverseTransform('/downloads/Book', {