Skip to content

Commit 68ecf78

Browse files
EslamHikohiroppy
authored andcommitted
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
1 parent eab6acd commit 68ecf78

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class Server {
405405
throw new Error('Watching remote files is not supported.');
406406
} else if (Array.isArray(contentBase)) {
407407
contentBase.forEach((item) => {
408-
if (isAbsoluteUrl(String(item))) {
408+
if (isAbsoluteUrl(String(item)) || typeof item === 'number') {
409409
throw new Error('Watching remote files is not supported.');
410410
}
411411
this._watch(item);

test/server/contentBase-option.test.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ describe('contentBase option', () => {
268268
});
269269

270270
describe('testing single & multiple external paths', () => {
271-
afterAll((done) => {
271+
afterEach((done) => {
272272
testServer.close(() => {
273273
done();
274274
});
@@ -301,6 +301,42 @@ describe('contentBase option', () => {
301301
done();
302302
}
303303
});
304+
it('Should not throw exception (local path with lower case first character)', (done) => {
305+
testServer.start(
306+
config,
307+
{
308+
contentBase:
309+
contentBasePublic.charAt(0).toLowerCase() +
310+
contentBasePublic.substring(1),
311+
watchContentBase: true,
312+
port,
313+
},
314+
done
315+
);
316+
});
317+
it("Should not throw exception (local path with lower case first character & has '-')", (done) => {
318+
testServer.start(
319+
config,
320+
{
321+
contentBase: 'c:\\absolute\\path\\to\\content-base',
322+
watchContentBase: true,
323+
port,
324+
},
325+
done
326+
);
327+
});
328+
it("Should not throw exception (local path with upper case first character & has '-')", (done) => {
329+
testServer.start(
330+
config,
331+
{
332+
contentBase: 'C:\\absolute\\path\\to\\content-base',
333+
watchContentBase: true,
334+
port,
335+
},
336+
done
337+
);
338+
});
339+
304340
it('Should throw exception (array)', (done) => {
305341
try {
306342
// eslint-disable-next-line no-unused-vars

0 commit comments

Comments
 (0)