Skip to content

Commit 7a96ebc

Browse files
hoodmanehedwigz
authored andcommitted
Don't normalize path in PATH.basename() (emscripten-core#23180)
This brings it in line with the behavior of basename im coreutils and node.
1 parent e974058 commit 7a96ebc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.75 (in development)
2222
-----------------------
23+
- `PATH.basename()` no longer calls `PATH.normalize()`, so that
24+
`PATH.basename("a/.")` returns `"."` instead of `"a"` and
25+
`PATH.basename("a/b/..")` returns `".."` instead of `"a"`. This is in line with
26+
the behaviour of both node and coreutils, and is already the case when using
27+
NODERAWFS". (#23180)
2328

2429
3.1.74 - 12/14/24
2530
-----------------

src/library_path.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ addToLibrary({
6464
return root + dir;
6565
},
6666
basename: (path) => {
67-
// EMSCRIPTEN return '/'' for '/', not an empty string
67+
// EMSCRIPTEN return '/' for '/', not an empty string
6868
if (path === '/') return '/';
69-
path = PATH.normalize(path);
70-
path = path.replace(/\/$/, "");
69+
path = path.replace(/\/+$/g, "");
7170
var lastSlash = path.lastIndexOf('/');
7271
if (lastSlash === -1) return path;
7372
return path.substr(lastSlash+1);

0 commit comments

Comments
 (0)