aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-08-08 22:03:18 +0800
committerGravatar GitHub <noreply@github.com> 2023-08-08 07:03:18 -0700
commit511f6bdf79ca64193219e5e9dcfa4bbc2717242a (patch)
tree122fe7713a835931d14f84f4121095c081c392ca /src
parent320ee6b6b78bb2b9752efff45e83167e532c0b9d (diff)
downloadbun-511f6bdf79ca64193219e5e9dcfa4bbc2717242a.tar.gz
bun-511f6bdf79ca64193219e5e9dcfa4bbc2717242a.tar.zst
bun-511f6bdf79ca64193219e5e9dcfa4bbc2717242a.zip
1. Check if the argument is an empty string in `path.format`. (#4064)
2. Avoid duplicating '/' at the beginning of the path. Close: #4005
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/node/types.zig21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index c858c9b04..02bfe8757 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -1861,14 +1861,17 @@ pub const Path = struct {
var insert_separator = true;
if (path_object.getTruthy(globalThis, "dir")) |prop| {
prop.toZigString(&dir, globalThis);
- insert_separator = !dir.isEmpty();
- } else if (path_object.getTruthy(globalThis, "root")) |prop| {
- prop.toZigString(&dir, globalThis);
+ }
+ if (dir.isEmpty()) {
+ if (path_object.getTruthy(globalThis, "root")) |prop| {
+ prop.toZigString(&dir, globalThis);
+ }
}
if (path_object.getTruthy(globalThis, "base")) |prop| {
prop.toZigString(&name_with_ext, globalThis);
- } else {
+ }
+ if (name_with_ext.isEmpty()) {
var had_ext = false;
if (path_object.getTruthy(globalThis, "ext")) |prop| {
prop.toZigString(&ext, globalThis);
@@ -1897,6 +1900,16 @@ pub const Path = struct {
defer allocator.free(out);
return JSC.ZigString.init(out).withEncoding().toValueGC(globalThis);
+ } else {
+ if (!isWindows) {
+ if (dir.eqlComptime("/")) {
+ insert_separator = false;
+ }
+ } else {
+ if (dir.eqlComptime("\\")) {
+ insert_separator = false;
+ }
+ }
}
if (insert_separator) {