From 68ecf78db36b63e2ba7f6dd2bff1f6dfef9f037f Mon Sep 17 00:00:00 2001 From: Eslam El-Hakmey Date: Thu, 22 Aug 2019 20:22:38 +0200 Subject: [PATCH] fix(server): use regex instead of isAbsoluteUrl (#2202) * fix(server): use regex instead of isAbsoluteUrl * fix(server): add checkUrl util & unistall is-absolute-url * test(server): add tests only * test(server): add more test cases * test: correct tests' values * test: use different port * test: use port variable * test: fix lint issue * test: use testServer.start without promises --- lib/Server.js | 2 +- test/server/contentBase-option.test.js | 38 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 239fe3783c..a403f4bbac 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -405,7 +405,7 @@ class Server { throw new Error('Watching remote files is not supported.'); } else if (Array.isArray(contentBase)) { contentBase.forEach((item) => { - if (isAbsoluteUrl(String(item))) { + if (isAbsoluteUrl(String(item)) || typeof item === 'number') { throw new Error('Watching remote files is not supported.'); } this._watch(item); diff --git a/test/server/contentBase-option.test.js b/test/server/contentBase-option.test.js index 3d6ab7de58..13acc53165 100644 --- a/test/server/contentBase-option.test.js +++ b/test/server/contentBase-option.test.js @@ -268,7 +268,7 @@ describe('contentBase option', () => { }); describe('testing single & multiple external paths', () => { - afterAll((done) => { + afterEach((done) => { testServer.close(() => { done(); }); @@ -301,6 +301,42 @@ describe('contentBase option', () => { done(); } }); + it('Should not throw exception (local path with lower case first character)', (done) => { + testServer.start( + config, + { + contentBase: + contentBasePublic.charAt(0).toLowerCase() + + contentBasePublic.substring(1), + watchContentBase: true, + port, + }, + done + ); + }); + it("Should not throw exception (local path with lower case first character & has '-')", (done) => { + testServer.start( + config, + { + contentBase: 'c:\\absolute\\path\\to\\content-base', + watchContentBase: true, + port, + }, + done + ); + }); + it("Should not throw exception (local path with upper case first character & has '-')", (done) => { + testServer.start( + config, + { + contentBase: 'C:\\absolute\\path\\to\\content-base', + watchContentBase: true, + port, + }, + done + ); + }); + it('Should throw exception (array)', (done) => { try { // eslint-disable-next-line no-unused-vars