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

scriptHost fix #2246

Merged
merged 3 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions client-src/default/utils/createSocketUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ function createSocketUrl(resourceQuery) {
// Else, get the url from the <script> this file was called with.
let scriptHost = getCurrentScriptSource();

// eslint-disable-next-line no-useless-escape
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
if (scriptHost) {
// eslint-disable-next-line no-useless-escape
scriptHost = scriptHost.replace(/\/[^\/]+$/, '');
}
urlParts = url.parse(scriptHost || '/', false, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ exports[`createSocketUrl should return the url when __resourceQuery is https://e

exports[`createSocketUrl should return the url when __resourceQuery is https://localhost:123 1`] = `"ttps:localhost:123/sockjs-node"`;

exports[`createSocketUrl should return the url when __resourceQuery is undefined 1`] = `"/sockjs-node"`;

exports[`createSocketUrl should return the url when the current script source is ?test 1`] = `"/sockjs-node"`;

exports[`createSocketUrl should return the url when the current script source is http://0.0.0.0 1`] = `"http:/sockjs-node"`;
Expand All @@ -31,3 +33,5 @@ exports[`createSocketUrl should return the url when the current script source is
exports[`createSocketUrl should return the url when the current script source is https://example.com/path/foo.js 1`] = `"https://example.com/sockjs-node"`;

exports[`createSocketUrl should return the url when the current script source is https://localhost:123 1`] = `"https:/sockjs-node"`;

exports[`createSocketUrl should return the url when the current script source is undefined 1`] = `"/sockjs-node"`;
2 changes: 2 additions & 0 deletions test/client/utils/createSocketUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('createSocketUrl', () => {
// TODO: comment out after the major release
// https://github.com/webpack/webpack-dev-server/pull/1954#issuecomment-498043376
// 'file://filename',
// eslint-disable-next-line no-undefined
undefined,
];

samples.forEach((url) => {
Expand Down