Skip to content

fix(client): stricter reg exp to redirect sockjs client path - #2069

Merged
hiroppy merged 6 commits into
webpack:masterfrom
knagaitsev:strict-reg-exp-fix
Jul 11, 2019
Merged

fix(client): stricter reg exp to redirect sockjs client path#2069
hiroppy merged 6 commits into
webpack:masterfrom
knagaitsev:strict-reg-exp-fix

Conversation

@knagaitsev

Copy link
Copy Markdown
Contributor
  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Yes

Motivation / Use-Case

Fixes problem introduced by #2015 using a stricter reg exp.

I added an iframe e2e test because the issue came up from users using iframe mode: #2006

Breaking Changes

None

Additional Info

@codecov

codecovBot commented Jun 25, 2019

Copy link
Copy Markdown

Codecov Report

Merging #2069 into master will increase coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@ Coverage Diff @@## master #2069 +/- ##
==========================================
+ Coverage 94.56% 94.65% +0.08% 
==========================================
Files 32 32 Lines 1215 1215 Branches 340 340 ==========================================
+ Hits 1149 1150 +1 + Misses 64 63 -1 
Partials 2 2
Impacted FilesCoverage Δ
lib/Server.js97.37% <0%> (+0.21%)⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bdf8444...c8d90ce. Read the comment docs.

);
}),
new webpack.NormalModuleReplacementPlugin(
/^\.\/clients\/SockJSClient$/,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need search way how we can check what module was loaded from our client-src - it is right way don't break other code

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

You mean to test that it is loading the correct module in the webpack compilation? Could we run this webpack config in a test, look at the webpack CLI output, and see if it contains the right path?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but it can solved using NormalModuleReplacementPlugin as you use, just need more checks (need check context contains 'webpack-dev-server/client-src' and rewrite only in this case)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

@evilebottnawi I did something like this, except instead I matched '/client-src/default', because it is possible the dev server is not in a webpack-dev-server directory if someone clones it into a different named directory. If we want to be very strict about it, we could match against path.resolve to get the exact context we want, but I'm afraid that could result in some problem.

Also, I included backwards slash (\\) in my matching string because windows seems to use that for the context paths

@alexander-akaitalexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just check if (resource.context.startsWith(process.cwd())) { }, we need rewrite clients only for webpack-dev-server, for other package it should be not rewritting

@knagaitsev

Copy link
Copy Markdown
ContributorAuthor

Just check if (resource.context.startsWith(process.cwd())) { }, we need rewrite clients only for webpack-dev-server, for other package it should be not rewritting

Done. Good solution!

@alexander-akaitalexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@hiroppy
hiroppy merged commit d3da508 into webpack:masterJul 11, 2019
knagaitsev added a commit to knagaitsev/webpack-dev-server that referenced this pull request Jul 31, 2019
…#2069)
* fix(client): stricter reg exp to redirect sockjs client path
* fix(client): check resource context for normal module replacement
* fix(client): remove dev server string from context path
* fix(client): remove console logs
* fix(client): fixed resource context match to use cwd
@knagaitsevknagaitsev added gsoc Google Summer of Code scope: ws(s) labels Aug 13, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gsocGoogle Summer of Codescope: ws(s)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@knagaitsev@hiroppy@alexander-akait@wizardofhogwarts