mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-07-10 15:00:15 +00:00
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:
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user