Skip to content

win32 path.normalize() not correctly normalizing relative paths containing ../ that advance above root #17928

Description

@peteward44
  • Version: 9.3.0
  • Platform: Windows 10 64bit
  • Subsystem: path

edit: See below comment for correct replication code

const path = require( 'path' );
const n = path.normalize( '../dir1/../../dir2' );
console.log( n );

Should output ../../dir2 but outputs dir2.

After some investigation it appears to have been introduced via commit b98e8d995efb426bbdee56ce503017bdcbbc6332 (path: fix normalize on directories with two dots)

Activity

  1. assigned and unassigned on Jan 2, 2018
  2. added
    pathIssues and PRs related to the path subsystem.
    windowsIssues and PRs related to the Windows platform.
    on Jan 2, 2018
  3. gibfahn commented on Jan 2, 2018

    @gibfahn
    Member

    cc/ @nodejs/platform-windows @targos

  4. gibfahn commented on Jan 2, 2018

    @gibfahn
    Member

    Can't reproduce on macOS, so assuming this is Windows specific.

  5. targos commented on Jan 2, 2018

    @targos
    Member

    Cant' reproduce on Windows either:

    > path.normalize('../dir1/../../dir2')
    '..\\..\\dir2'
    
  6. peteward44 commented on Jan 2, 2018

    @peteward44
    Author

    This is strange, let me take another look to see what's happening

  7. peteward44 commented on Jan 2, 2018

    @peteward44
    Author

    OK - my example was bad. Sorry about that, try this:

    path.normalize( '../../../dir1/../../../dir2' );

    Should output ../../../../../dir2 but outputs ../dir2

  8. removed
    windowsIssues and PRs related to the Windows platform.
    on Jan 2, 2018
  9. gibfahn commented on Jan 2, 2018

    @gibfahn
    Member

    Okay, can reproduce that with v6.12.0 but not v6.11.5 (on macOS), which suggests b98e8d9 is indeed the cause of the issue.

    ▶▶▶ nvm i v6.11.5                                                                                                                                                 ~/wrk/com/DANGER/node (v8.9.4-proposal)
    v6.11.5 is already installed.
    Now using node v6.11.5 (npm v3.10.10)
    ▶▶▶ node -p "path.normalize( '../../../dir1/../../../dir2' );"                                                                                                 ~/wrk/com/DANGER/node 2s (v8.9.4-proposal)
    ../../../../../dir2
    ▶▶▶ nvm use 6.12.0                                                                                                                                                ~/wrk/com/DANGER/node (v8.9.4-proposal)
    Now using node v6.12.0 (npm v3.10.10)
    ▶▶▶ node -p "path.normalize( '../../../dir1/../../../dir2' );"                                                                                                 ~/wrk/com/DANGER/node 1s (v8.9.4-proposal)
    ../dir2
  10. peteward44 commented on Jan 3, 2018

    @peteward44
    Author

    Cool, i would have submitted a PR myself but i was unsure of the correct behaviour that b98e8d9 was supposed to fix. Thanks for looking at this 👍

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.pathIssues and PRs related to the path subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions