1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

fixing url concatenation bug

This commit is contained in:
Patrik J. Braun 2019-01-19 13:00:38 +01:00
parent ca33bb1efb
commit 0e3b04c122
2 changed files with 20 additions and 2 deletions

View File

@ -90,14 +90,14 @@ export class Utils {
continue; continue;
} }
const part = args[i].replace('\\', '/'); const part = args[i].replace(new RegExp('\\\\', 'g'), '/');
if (part === '/' || part === './') { if (part === '/' || part === './') {
continue; continue;
} }
url += part + '/'; url += part + '/';
} }
url = url.replace('//', '/'); url = url.replace(new RegExp('/+', 'g'), '/');
if (url.trim() === '') { if (url.trim() === '') {
url = './'; url = './';

View File

@ -0,0 +1,18 @@
import {expect} from 'chai';
import {Utils} from '../../../common/Utils';
describe('Utils', () => {
it('should concat urls', () => {
expect(Utils.concatUrls('abc', 'cde')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc/', 'cde')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc\\', 'cde')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc/', 'cde/')).to.be.equal('abc/cde');
expect(Utils.concatUrls('./abc\\', 'cde/')).to.be.equal('./abc/cde');
expect(Utils.concatUrls('abc/', '\\cde/')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc\\', '\\cde/')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc\\', '/cde/')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc/', '/cde/')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc\\/', '/cde/')).to.be.equal('abc/cde');
expect(Utils.concatUrls('abc\\/', '/cde/', 'fgh')).to.be.equal('abc/cde/fgh');
});
});