1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop: Resolves #10424: Move the note viewer to a separate process (#10678)

This commit is contained in:
Henry Heino
2024-07-26 04:22:49 -07:00
committed by GitHub
parent 4b99c2062c
commit d2028588e8
25 changed files with 581 additions and 29 deletions

View File

@ -0,0 +1,38 @@
import resolvePathWithinDir from './resolvePathWithinDir';
describe('resolvePathWithinDir', () => {
test('should return correct values for Unix-style paths', () => {
const testCases = [
// Absolute paths
{ baseDir: '/a/test/path/', path: '/a/test/path/test.txt', expected: '/a/test/path/test.txt' },
{ baseDir: '/a/test/path/', path: '/a/test/path/..test.txt', expected: '/a/test/path/..test.txt' },
{ baseDir: '/a/test/path/', path: '/a/test/path/.test.txt', expected: '/a/test/path/.test.txt' },
{ baseDir: '/a/test/path', path: '/a/test/path/.test.txt', expected: '/a/test/path/.test.txt' },
{ baseDir: '/a/test/path', path: '/a/test/path', expected: '/a/test/path' },
{ baseDir: '/a/test/path', path: '/a/', expected: null },
{ baseDir: '/a/test/path', path: '/a/test/', expected: null },
{ baseDir: '/a/test/path', path: '/a/test/pa', expected: null },
{ baseDir: '/a/test/path', path: '/a/test/path2', expected: null },
{ baseDir: '/a/test/path', path: '/a/test/path\\//subdir', expected: null },
// Relative paths
{ baseDir: '/a/test/path', path: './test', expected: '/a/test/path/test' },
{ baseDir: '/a/test/path', path: '../path/test/2', expected: '/a/test/path/test/2' },
{ baseDir: '/a/test/path', path: '../path/test/../../../2', expected: null },
{ baseDir: '/a/test/path', path: '../test', expected: null },
];
for (const testCase of testCases) {
expect(resolvePathWithinDir(testCase.baseDir, testCase.path, false)).toBe(testCase.expected);
}
});
test('should return correct values for Windows-style paths', () => {
expect(resolvePathWithinDir('C:\\a\\test\\path', 'C:\\a\\test\\path\\2', true)).toBe('C:\\a\\test\\path\\2');
expect(resolvePathWithinDir('C:\\\\a\\test\\path', '.\\path\\2', true)).toBe('C:\\a\\test\\path\\path\\2');
expect(resolvePathWithinDir('C:\\a\\test\\path', '..\\path\\2', true)).toBe('C:\\a\\test\\path\\2');
expect(resolvePathWithinDir('C:\\a\\test\\path', '..\\2', true)).toBe(null);
expect(resolvePathWithinDir('D:\\a\\test\\path', 'C:\\a\\test\\path\\2', true)).toBe(null);
expect(resolvePathWithinDir('\\a\\test\\path', 'D:\\a\\test\\path\\2', true)).toBe(null);
});
});