Skip to content

Commit

Permalink
fix(server): use regex instead of isAbsoluteUrl (#2202)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
EslamHiko authored and hiroppy committed Aug 22, 2019
1 parent eab6acd commit 68ecf78
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 37 additions & 1 deletion test/server/contentBase-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe('contentBase option', () => {
});

describe('testing single & multiple external paths', () => {
afterAll((done) => {
afterEach((done) => {
testServer.close(() => {
done();
});
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 68ecf78

Please sign in to comment.