mirror of https://github.com/keeweb/keeweb.git
url format tests
This commit is contained in:
parent
b96b477f65
commit
c6c307c50c
|
@ -1,6 +1,6 @@
|
|||
const UrlFormat = {
|
||||
multiSlashRegex: /\/{2,}/g,
|
||||
lastPartRegex: /\/?[^\/\\]+$/,
|
||||
lastPartRegex: /[\/\\]?[^\/\\]+$/,
|
||||
kdbxEndRegex: /\.kdbx$/i,
|
||||
|
||||
getDataFileName(url) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import { expect } from 'chai';
|
||||
import { UrlFormat } from 'util/formatting/url-format';
|
||||
|
||||
describe('UrlFormat', () => {
|
||||
it('should extract file name from url', () => {
|
||||
expect(UrlFormat.getDataFileName('https://example.com/data/My.file.kDBx?x=1')).to.eql(
|
||||
'My.file'
|
||||
);
|
||||
});
|
||||
|
||||
it('should determine if url represents a kdbx file', () => {
|
||||
expect(UrlFormat.isKdbx('//data/file.KdBx')).to.be.true;
|
||||
expect(UrlFormat.isKdbx('//data/file.kdb')).to.be.false;
|
||||
expect(UrlFormat.isKdbx('//data/file.kdbxx')).to.be.false;
|
||||
});
|
||||
|
||||
it('should replace multiple slashes', () => {
|
||||
expect(UrlFormat.fixSlashes('//data/file//ext')).to.eql('/data/file/ext');
|
||||
});
|
||||
|
||||
it('should get directory url by full url', () => {
|
||||
expect(UrlFormat.fileToDir('/var/data/My.file.kdbx')).to.eql('/var/data');
|
||||
expect(UrlFormat.fileToDir('\\\\share\\data\\My.file.kdbx')).to.eql('\\\\share\\data');
|
||||
expect(UrlFormat.fileToDir('My.file.kdbx')).to.eql('/');
|
||||
});
|
||||
|
||||
it('should make url from parts', () => {
|
||||
expect(
|
||||
UrlFormat.makeUrl('/path', {
|
||||
hello: 'world',
|
||||
data: '= &'
|
||||
})
|
||||
).to.eql('/path?hello=world&data=%3D%20%26');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue