@@ -125,16 +125,16 @@ pub const URL = struct {
125125 }
126126 };
127127
128+ const normalized_src = if (src [0 ] == '/' ) src [1.. ] else src ;
129+
128130 if (std .mem .lastIndexOfScalar (u8 , base [protocol_end .. ], '/' )) | index | {
129131 const last_slash_pos = index + protocol_end ;
130132 if (last_slash_pos == base .len - 1 ) {
131- return std .fmt .allocPrint (allocator , "{s}{s}" , .{ base , src });
132- } else {
133- return std .fmt .allocPrint (allocator , "{s}/{s}" , .{ base [0.. last_slash_pos ], src });
133+ return std .fmt .allocPrint (allocator , "{s}{s}" , .{ base , normalized_src });
134134 }
135- } else {
136- return std .fmt .allocPrint (allocator , "{s}/{s}" , .{ base , src });
135+ return std .fmt .allocPrint (allocator , "{s}/{s}" , .{ base [0.. last_slash_pos ], normalized_src });
137136 }
137+ return std .fmt .allocPrint (allocator , "{s}/{s}" , .{ base , normalized_src });
138138 }
139139
140140 pub fn concatQueryString (arena : Allocator , url : []const u8 , query_string : []const u8 ) ! []const u8 {
@@ -233,6 +233,16 @@ test "URL: Stitching Base & Src URLs (Just Ending Slash)" {
233233 try testing .expectString ("https://www.google.com/something.js" , result );
234234}
235235
236+ test "URL: Stitching Base & Src URLs with leading slash" {
237+ const allocator = testing .allocator ;
238+
239+ const base = "https://www.google.com/" ;
240+ const src = "/something.js" ;
241+ const result = try URL .stitch (allocator , src , base , .{});
242+ defer allocator .free (result );
243+ try testing .expectString ("https://www.google.com/something.js" , result );
244+ }
245+
236246test "URL: Stitching Base & Src URLs (No Ending Slash)" {
237247 const allocator = testing .allocator ;
238248
0 commit comments