Skip to content

Trailing slash causes different behavior in Path.resolve and Url.resolve #3769

@ivan-kleshnin

Description

@ivan-kleshnin
import Url from "url";
import Path from "path";

// Example 1 ==================
let dir = "/uploads/foo/"; // trailing slash
let filename = "bar.jpg";

Url.resolve(dir, filename);  // "/uploads/foo/bar.jpg"
Path.resolve(dir, filename); // "/uploads/foo/bar.jpg "
// Url.resolve <=> Path.resolve

// Example 2 ===================
let dir = "/uploads/foo"; // no trailing slash
let filename = "bar.jpg";

Url.resolve(dir, filename);  // "/uploads/bar.jpg"
Path.resolve(dir, filename); // "/uploads/foo/bar.jpg"
// // Url.resolve <!=> Path.resolve

I expected from Url.resolve and Path.resolve to return the same result with that inputs.
Trailing slash is a weak condition to depend IMO.

Node v4.2.2
OS X 10.9.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    pathIssues and PRs related to the path subsystem.urlIssues and PRs related to the legacy built-in url module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions