Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): use regex instead of isAbsoluteUrl #2202

Merged
merged 11 commits into from Aug 22, 2019
2 changes: 1 addition & 1 deletion lib/Server.js
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we add typeof item === 'number'?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi it's already blocking number values in options.js accepting only strings, in case in future refactors if we change the type of array items to accept any type we still need it to throw an exception if the array item is number type.

Copy link
Member Author

@EslamHiko EslamHiko Aug 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi we can remove number type from options.json

  "contentBase": {
      "anyOf": [
        {
          "enum": [false]
        },
        {
          "type": "number"
        },
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1
        }
      ]
    },

and remove || typeof item === 'number' checks and update tests to check for the exception "should be {String|Array} (https://webpack.js.org/configuration/dev-server/#devservercontentbase)" in number type cases
what do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it next version

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
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