diff --git a/common/Utils.ts b/common/Utils.ts index de5a8dcf..f33c68d5 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -90,14 +90,14 @@ export class Utils { continue; } - const part = args[i].replace('\\', '/'); + const part = args[i].replace(new RegExp('\\\\', 'g'), '/'); if (part === '/' || part === './') { continue; } url += part + '/'; } - url = url.replace('//', '/'); + url = url.replace(new RegExp('/+', 'g'), '/'); if (url.trim() === '') { url = './'; diff --git a/test/common/unit/Utils.spec.ts b/test/common/unit/Utils.spec.ts new file mode 100644 index 00000000..6895a564 --- /dev/null +++ b/test/common/unit/Utils.spec.ts @@ -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'); + }); +});