Skip to content

pathe.basename behaves differently w/ path.basename when handling trailing separator #179

@SukkaW

Description

@SukkaW

Environment

Node.js 18 & 22

Reproduction

const path = require("path");
const pathe = require("pathe");

console.log({
  path: path.basename("sbin/a/"),
  pathe: pathe.basename("sbin/a/"),
});

// { path: 'a', pathe: '' }

console.log({
  path: path.basename("sbin/a///"),
  pathe: pathe.basename("sbin/a///"),
});

// { path: 'a', pathe: '' }

https://replit.com/@isukkaw/ColossalGloriousWamp

Describe the bug

pathe.basename("sbin/a/") should return a instead of an empty string.

Additional context

Per Node.js basename documents: https://nodejs.org/api/path.html#pathbasenamepath-suffix

Trailing directory separators are ignored.

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions