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

path.normalize not work well with windows style path on linux platform #4564

Closed
iahu opened this issue Jan 7, 2016 · 4 comments
Closed

path.normalize not work well with windows style path on linux platform #4564

iahu opened this issue Jan 7, 2016 · 4 comments
Labels
path Issues and PRs related to the path subsystem.

Comments

@iahu
Copy link

iahu commented Jan 7, 2016

Hi, I have a test case of normalize a windows style "path string" on linux platform.

on linux

path.normalize('\\pic\\..\\2016'); // -> \\pic\\..\\2016, expected return /pic/2016

but on windows

path.normalize('/a/b/../c.js'); // -> \\a\\c.js

The questions are:

  1. windows sep not replace with linux sep.
  2. '..' part not works.
@mscdex mscdex added the path Issues and PRs related to the path subsystem. label Jan 7, 2016
@targos
Copy link
Member

targos commented Jan 7, 2016

Do you know before calling normalize that the path has Windows style ?
If so, you can explicitly call path.win32.normalize(thepath)

@mscdex
Copy link
Contributor

mscdex commented Jan 7, 2016

You can already access platform-specific path.* methods via the path.posix and path.win32 namespaces. Is that what you're after?

@iahu
Copy link
Author

iahu commented Jan 7, 2016

Yes, path.win32 and path.posix is just what I want. Thanks @targos and @mscdex .

Unfortunately, I run a 0.10.30 version node. that not important, I have change my code to fix this failing. : )

I think path.normalize should be more "smarter".

There are no need use path.posix.normalize on windows version, because path.normalize just work well. but I doubt why linux version path.normalize not treat win-style path lick windows version treat with unix-style path, processing all the sep '\' and '..' well. That's strange.

@bnoordhuis
Copy link
Member

why linux version path.normalize not treat win-style path lick windows version treat with unix-style path, processing all the sep '' and '..' well

Because on UNIX the backslash is a valid character inside a path component, i.e., it's not a separator. On Windows, the forward slash and the backward slash are both separators. Closing, not a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
path Issues and PRs related to the path subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants