aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-22 16:19:25 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-09-22 16:19:25 -0700
commitf12dd51c006b3df0f99fda77800c7778225fccff (patch)
tree39462d7c90670e3e3eb6f23e65899ac52395eac1
parente00c1e99d67ff6224dcfb783c84ced9896537cb0 (diff)
downloadbun-f12dd51c006b3df0f99fda77800c7778225fccff.tar.gz
bun-f12dd51c006b3df0f99fda77800c7778225fccff.tar.zst
bun-f12dd51c006b3df0f99fda77800c7778225fccff.zip
Update query_string_map.zig
-rw-r--r--src/query_string_map.zig20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/query_string_map.zig b/src/query_string_map.zig
index 4c451806d..4b7e9e1d5 100644
--- a/src/query_string_map.zig
+++ b/src/query_string_map.zig
@@ -158,11 +158,17 @@ pub const URL = struct {
try writer.print("{s}/{s}", .{ this.origin, normalized_path });
}
- pub fn joinAlloc(this: *const URL, allocator: *std.mem.Allocator, prefix: string, dirname: string, basename: string, extname: string) !string {
- var out: [2048]u8 = undefined;
- const normalized_path = joinNormalize(&out, prefix, dirname, basename, extname);
+ pub fn joinAlloc(this: *const URL, allocator: *std.mem.Allocator, prefix: string, dirname: string, basename: string, extname: string, absolute_path: string) !string {
+ const has_uplevels = std.mem.indexOf(u8, dirname, "../") != null;
- return try std.fmt.allocPrint(allocator, "{s}/{s}", .{ this.origin, normalized_path });
+ if (has_uplevels) {
+ return try std.fmt.allocPrint(allocator, "{s}/abs:{s}", .{ this.origin, absolute_path });
+ } else {
+ var out: [2048]u8 = undefined;
+
+ const normalized_path = joinNormalize(&out, prefix, dirname, basename, extname);
+ return try std.fmt.allocPrint(allocator, "{s}/{s}", .{ this.origin, normalized_path });
+ }
}
pub fn parse(base_: string) URL {
@@ -1330,11 +1336,11 @@ test "URL - joinAlloc" {
var url = URL.parse("http://localhost:3000");
var absolute_url = try url.joinAlloc(default_allocator, "/_next/", "src/components", "button", ".js");
- try expectString("http://localhost:3000/_next/src/components/button.js", absolute_url);
+ try expectString("http://localhost:3000/_next/src/components/button.js", absolute_url, "");
absolute_url = try url.joinAlloc(default_allocator, "compiled-", "src/components", "button", ".js");
- try expectString("http://localhost:3000/compiled-src/components/button.js", absolute_url);
+ try expectString("http://localhost:3000/compiled-src/components/button.js", absolute_url, "");
absolute_url = try url.joinAlloc(default_allocator, "compiled-", "", "button", ".js");
- try expectString("http://localhost:3000/compiled-button.js", absolute_url);
+ try expectString("http://localhost:3000/compiled-button.js", absolute_url, "");
}