@@ -110,7 +110,13 @@ pub const URL = struct {
110110 }
111111 return src ;
112112 }
113- if (src .len == 0 ) {
113+
114+ var normalized_src = if (std .mem .startsWith (u8 , src , "/" )) src [1.. ] else src ;
115+ while (std .mem .startsWith (u8 , normalized_src , "./" )) {
116+ normalized_src = normalized_src [2.. ];
117+ }
118+
119+ if (normalized_src .len == 0 ) {
114120 if (opts .alloc == .always ) {
115121 return allocator .dupe (u8 , base );
116122 }
@@ -125,8 +131,6 @@ pub const URL = struct {
125131 }
126132 };
127133
128- const normalized_src = if (src [0 ] == '/' ) src [1.. ] else src ;
129-
130134 if (std .mem .lastIndexOfScalar (u8 , base [protocol_end .. ], '/' )) | index | {
131135 const last_slash_pos = index + protocol_end ;
132136 if (last_slash_pos == base .len - 1 ) {
@@ -216,41 +220,41 @@ test "URL: resolve size" {
216220test "URL: Stitching Base & Src URLs (Basic)" {
217221 const allocator = testing .allocator ;
218222
219- const base = "https://www.google.com /xyz/abc/123" ;
223+ const base = "https://lightpanda.io /xyz/abc/123" ;
220224 const src = "something.js" ;
221225 const result = try URL .stitch (allocator , src , base , .{});
222226 defer allocator .free (result );
223- try testing .expectString ("https://www.google.com /xyz/abc/something.js" , result );
227+ try testing .expectString ("https://lightpanda.io /xyz/abc/something.js" , result );
224228}
225229
226230test "URL: Stitching Base & Src URLs (Just Ending Slash)" {
227231 const allocator = testing .allocator ;
228232
229- const base = "https://www.google.com /" ;
233+ const base = "https://lightpanda.io /" ;
230234 const src = "something.js" ;
231235 const result = try URL .stitch (allocator , src , base , .{});
232236 defer allocator .free (result );
233- try testing .expectString ("https://www.google.com /something.js" , result );
237+ try testing .expectString ("https://lightpanda.io /something.js" , result );
234238}
235239
236240test "URL: Stitching Base & Src URLs with leading slash" {
237241 const allocator = testing .allocator ;
238242
239- const base = "https://www.google.com /" ;
243+ const base = "https://lightpanda.io /" ;
240244 const src = "/something.js" ;
241245 const result = try URL .stitch (allocator , src , base , .{});
242246 defer allocator .free (result );
243- try testing .expectString ("https://www.google.com /something.js" , result );
247+ try testing .expectString ("https://lightpanda.io /something.js" , result );
244248}
245249
246250test "URL: Stitching Base & Src URLs (No Ending Slash)" {
247251 const allocator = testing .allocator ;
248252
249- const base = "https://www.google.com " ;
253+ const base = "https://lightpanda.io " ;
250254 const src = "something.js" ;
251255 const result = try URL .stitch (allocator , src , base , .{});
252256 defer allocator .free (result );
253- try testing .expectString ("https://www.google.com /something.js" , result );
257+ try testing .expectString ("https://lightpanda.io /something.js" , result );
254258}
255259
256260test "URL: Stiching Base & Src URLs (Both Local)" {
@@ -275,11 +279,21 @@ test "URL: Stiching src as full path" {
275279test "URL: Stitching Base & Src URLs (empty src)" {
276280 const allocator = testing .allocator ;
277281
278- const base = "https://www.google.com /xyz/abc/123" ;
282+ const base = "https://lightpanda.io /xyz/abc/123" ;
279283 const src = "" ;
280284 const result = try URL .stitch (allocator , src , base , .{});
281285 defer allocator .free (result );
282- try testing .expectString ("https://www.google.com/xyz/abc/123" , result );
286+ try testing .expectString ("https://lightpanda.io/xyz/abc/123" , result );
287+ }
288+
289+ test "URL: Stitching dotslash" {
290+ const allocator = testing .allocator ;
291+
292+ const base = "https://lightpanda.io/hello/" ;
293+ const src = "./something.js" ;
294+ const result = try URL .stitch (allocator , src , base , .{});
295+ defer allocator .free (result );
296+ try testing .expectString ("https://lightpanda.io/hello/something.js" , result );
283297}
284298
285299test "URL: concatQueryString" {
0 commit comments