Skip to content

Commit

Permalink
add test and tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgunday committed Feb 23, 2025
1 parent 931c797 commit 7d2cab1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ const win32 = {

const code = StringPrototypeCharCodeAt(path, 0);
if (len === 1) return isPathSeparator(code) ? path : '.';
if (len === 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 1))) return path;
if (len === 2 && isPathSeparator(StringPrototypeCharCodeAt(path, 1))) return isPathSeparator(code) ? path[0] : '.';

let rootEnd = -1;
let offset = 0;
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-path-dirname.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ assert.strictEqual(path.dirname(__filename).slice(-13),

assert.strictEqual(path.posix.dirname('/a/b/'), '/a');
assert.strictEqual(path.posix.dirname('/a/b'), '/a');
assert.strictEqual(path.posix.dirname('a/'), '.');
assert.strictEqual(path.posix.dirname('/a'), '/');
assert.strictEqual(path.posix.dirname(''), '.');
assert.strictEqual(path.posix.dirname('ab'), '.');
assert.strictEqual(path.posix.dirname('/'), '/');
assert.strictEqual(path.posix.dirname('//'), '/');
assert.strictEqual(path.posix.dirname('////'), '/');
assert.strictEqual(path.posix.dirname('//a'), '//');
assert.strictEqual(path.posix.dirname('foo'), '.');
Expand Down Expand Up @@ -53,6 +56,9 @@ assert.strictEqual(path.win32.dirname('\\\\unc\\share\\foo\\bar\\baz'),
assert.strictEqual(path.win32.dirname('/a/b/'), '/a');
assert.strictEqual(path.win32.dirname('/a/b'), '/a');
assert.strictEqual(path.win32.dirname('/a'), '/');
assert.strictEqual(path.win32.dirname('a/'), '.');
assert.strictEqual(path.win32.dirname('ab'), '.');
assert.strictEqual(path.win32.dirname('//'), '/');
assert.strictEqual(path.win32.dirname(''), '.');
assert.strictEqual(path.win32.dirname('/'), '/');
assert.strictEqual(path.win32.dirname('////'), '/');
Expand Down

0 comments on commit 7d2cab1

Please sign in to comment.