[FIX] Download my data with file uploads (#19862)
parent
19e696784e
commit
f5c7d94bff
@ -0,0 +1,28 @@ |
||||
/* eslint-env mocha */ |
||||
import { expect } from 'chai'; |
||||
|
||||
import { fileName, joinPath } from './fileUtils'; |
||||
|
||||
describe('File utils', () => { |
||||
it('should return a valid file name', () => { |
||||
expect(fileName('something')).to.equal('something'); |
||||
expect(fileName('some@thing')).to.equal('some@thing'); |
||||
expect(fileName('/something')).to.equal('something'); |
||||
expect(fileName('/some/thing')).to.equal('some-thing'); |
||||
expect(fileName('/some/thing/')).to.equal('some-thing'); |
||||
expect(fileName('///some///thing///')).to.equal('some-thing'); |
||||
expect(fileName('some/thing')).to.equal('some-thing'); |
||||
expect(fileName('some:"thing"')).to.equal('some-thing'); |
||||
expect(fileName('some:"thing".txt')).to.equal('some-thing-.txt'); |
||||
expect(fileName('some"thing"')).to.equal('some-thing'); |
||||
expect(fileName('some\u0000thing')).to.equal('some-thing'); |
||||
}); |
||||
it('should return a valid joined path', () => { |
||||
expect(joinPath('/app', 'some@thing')).to.equal('/app/some@thing'); |
||||
expect(joinPath('../app', 'something')).to.equal('../app/something'); |
||||
expect(joinPath('../app/', 'something')).to.equal('../app/something'); |
||||
expect(joinPath('../app/', '/something')).to.equal('../app/something'); |
||||
expect(joinPath('/app', '/something')).to.equal('/app/something'); |
||||
expect(joinPath('/app', '/../some/thing')).to.equal('/app/..-some-thing'); |
||||
}); |
||||
}); |
@ -0,0 +1,11 @@ |
||||
import path from 'path'; |
||||
|
||||
import filenamify from 'filenamify'; |
||||
|
||||
export function fileName(name: string): string { |
||||
return filenamify(name, { replacement: '-' }); |
||||
} |
||||
|
||||
export function joinPath(base: string, name: string): string { |
||||
return path.join(base, fileName(name)); |
||||
} |
Loading…
Reference in new issue