Simplify
This commit is contained in:
32
src/lib/index.test.ts
Normal file
32
src/lib/index.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import safePath from '$lib';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('safe path', () => {
|
||||
it('reject names with ../', () => {
|
||||
expect(safePath('./uplodas', '../foobar')).toBe(false);
|
||||
});
|
||||
|
||||
it('accept names with ./', () => {
|
||||
expect(safePath('./uplodas', './foobar')).toBe(true);
|
||||
});
|
||||
|
||||
it('reject names with /', () => {
|
||||
expect(safePath('./uplodas', 'foo/bar')).toBe(false);
|
||||
});
|
||||
|
||||
it('accept happy path', () => {
|
||||
expect(safePath('./uplodas', 'foobar')).toBe(true);
|
||||
});
|
||||
|
||||
it('accept names starting with `..`', () => {
|
||||
expect(safePath('./uplodas', '..foobar')).toBe(true);
|
||||
});
|
||||
|
||||
it('accept names ending with `..`', () => {
|
||||
expect(safePath('./uplodas', 'foobar..')).toBe(true);
|
||||
});
|
||||
|
||||
it('accept names starting and ending with `..`', () => {
|
||||
expect(safePath('./uplodas', '..foobar..')).toBe(true);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user