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: replace url-join with path.posix.join #334

Merged
merged 7 commits into from
Sep 21, 2018

Conversation

haoqunjiang
Copy link
Contributor

@haoqunjiang haoqunjiang commented Aug 25, 2018

@jsf-clabot
Copy link

jsf-clabot commented Aug 25, 2018

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Aug 25, 2018

Codecov Report

Merging #334 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #334   +/-   ##
=======================================
  Coverage   96.82%   96.82%           
=======================================
  Files           7        7           
  Lines         252      252           
=======================================
  Hits          244      244           
  Misses          8        8
Impacted Files Coverage Δ
lib/middleware.js 94.23% <100%> (ø) ⬆️
lib/util.js 100% <100%> (ø) ⬆️

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 610e260...e642b9d. Read the comment docs.

@haoqunjiang haoqunjiang changed the title fix: replace url-join with path.join, fixes #333 fix: replace url-join with path.posix.join, fixes #333 Aug 25, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix: replace url-join with path.posix.join, fixes #333 fix: replace url-join with path.posix.join Aug 25, 2018
@michael-ciniawsky
Copy link
Member

@sodatea Happy to see it go an use a core module instead, but windows test are currently failing with this patch https://ci.appveyor.com/project/sokra/webpack-dev-middleware/build/1.0.110/job/fxenmru3b8ujigbt

@@ -278,41 +284,41 @@ describe('GetFilenameFromUrl', () => {
url: '/test/windows.txt',
outputPath: 'c:\\foo',
publicPath: '/test',
// this is weird, but it's legal-ish, and what URI parsing produces
expected: 'c://\\foo/windows.txt'
Copy link
Member

@michael-ciniawsky michael-ciniawsky Aug 26, 2018

Choose a reason for hiding this comment

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

We need ro make sure this is valid to be removed, windows paths recognize both separators to my knowledge and this therefore will fail for some folks having / in their paths for whatever reason :) Can you elaborate on why this can be removed please ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#276

Where we might expect c:\foo\bar we instead get a URL-ized c://\foo/bar. Either works with the default path translation on Windows, though technically it's wrong.

If I understand correctly, the // is not indended to be preserved but now that it still works we didn’t bother removing it.

Copy link
Member

@michael-ciniawsky michael-ciniawsky Aug 26, 2018

Choose a reason for hiding this comment

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

Could you try with path.normalize and leaving the expected values ?

const filename = path.posix.join(path.normalize(...), ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After refactoring those Windows-specific tests still passes (path.posix.join(path.normalize('C:\\foo'), 'windows.txt') returns C:\\foo/windows.txt)
But a lot of other tests failed for unknown reason. So I suppose my initial implementation is legit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Paths are not URLs there must be a reason why url-join was used here instead. I didn't write this code so I'm not sure if 'this only handles file paths' renders 💯 true. I think the issue with path.nomalize was, that we would need to use the path.posix variant instead

- const filename = path.posix.join(path.normalize(...), ...)
+ const filename = path.posix.join(path.posix.normalize(...), ...)

But leave it for now until we know how to proceed here in general :)

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #334 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #334   +/-   ##
=======================================
  Coverage   96.82%   96.82%           
=======================================
  Files           7        7           
  Lines         252      252           
=======================================
  Hits          244      244           
  Misses          8        8
Impacted Files Coverage Δ
lib/middleware.js 94.23% <100%> (ø) ⬆️
lib/util.js 100% <100%> (ø) ⬆️

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 610e260...e642b9d. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 18, 2018

Codecov Report

Merging #334 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #334      +/-   ##
==========================================
- Coverage   96.82%   96.81%   -0.02%     
==========================================
  Files           7        7              
  Lines         252      251       -1     
==========================================
- Hits          244      243       -1     
  Misses          8        8
Impacted Files Coverage Δ
lib/middleware.js 94.33% <100%> (ø) ⬆️
lib/util.js 100% <100%> (ø) ⬆️

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 0f9e2e7...1fbcac6. Read the comment docs.

@@ -1,7 +1,7 @@
'use strict';

const path = require('path');
Copy link
Member

Choose a reason for hiding this comment

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

const { join } = require('path')

@alexander-akait
Copy link
Member

/cc @michael-ciniawsky

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

Looks good let's try it, I still wonder why url-join was used here in the first place...

@sodatea Thx

@@ -1,7 +1,7 @@
'use strict';

const { posix: { join } } = require('path');
Copy link
Member

Choose a reason for hiding this comment

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

Please just use const path = require('path' ) ... path.posix.join(...) like you did in lib/util.js

lib/util.js Outdated
@@ -1,10 +1,10 @@
'use strict';

const path = require('path');
const { parse } = require('url');
const querystring = require('querystring');
const pathabs = require('path-is-absolute');
Copy link
Member

@michael-ciniawsky michael-ciniawsky Sep 19, 2018

Choose a reason for hiding this comment

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

This should be gone by now #335. Could you rebase with the PR with latest master to ensure we won't get a bad merge here please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 😄

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't seemed to be the case the line is still there (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, sorry, forgot to push -f 😅
Should be fixed now.

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Sep 21, 2018

@sodatea Since this removes a dependency could you update the lockfile please? Otherwise this is ready to land

Copy link
Member

@michael-ciniawsky michael-ciniawsky left a comment

Choose a reason for hiding this comment

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

@sodatea Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants