mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
Don't allow timeouts to be registered when shutting down
Currently, a timeout that sets a timeout can cause loop.run to block forever. Also, cleanup URL stitch with leading './'. The resulting URL was valid, but since we use the URL as the module cache key, it's important to resolve various representations of the same URL in the same way.
This commit is contained in:
@@ -187,6 +187,12 @@ pub const Loop = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn timeout(self: *Self, nanoseconds: u63, callback_node: ?*CallbackNode) !usize {
|
pub fn timeout(self: *Self, nanoseconds: u63, callback_node: ?*CallbackNode) !usize {
|
||||||
|
if (self.stopping) {
|
||||||
|
// Prevents a timeout callback from creating a new timeout, which
|
||||||
|
// would make `loop.run` run forever.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const completion = try self.alloc.create(Completion);
|
const completion = try self.alloc.create(Completion);
|
||||||
errdefer self.alloc.destroy(completion);
|
errdefer self.alloc.destroy(completion);
|
||||||
completion.* = undefined;
|
completion.* = undefined;
|
||||||
|
|||||||
40
src/url.zig
40
src/url.zig
@@ -110,7 +110,13 @@ pub const URL = struct {
|
|||||||
}
|
}
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
if (src.len == 0) {
|
|
||||||
|
var normalized_src = if (std.mem.startsWith(u8, src, "/")) src[1..] else src;
|
||||||
|
while (std.mem.startsWith(u8, normalized_src, "./")) {
|
||||||
|
normalized_src = normalized_src[2..];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (normalized_src.len == 0) {
|
||||||
if (opts.alloc == .always) {
|
if (opts.alloc == .always) {
|
||||||
return allocator.dupe(u8, base);
|
return allocator.dupe(u8, base);
|
||||||
}
|
}
|
||||||
@@ -125,8 +131,6 @@ pub const URL = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const normalized_src = if (src[0] == '/') src[1..] else src;
|
|
||||||
|
|
||||||
if (std.mem.lastIndexOfScalar(u8, base[protocol_end..], '/')) |index| {
|
if (std.mem.lastIndexOfScalar(u8, base[protocol_end..], '/')) |index| {
|
||||||
const last_slash_pos = index + protocol_end;
|
const last_slash_pos = index + protocol_end;
|
||||||
if (last_slash_pos == base.len - 1) {
|
if (last_slash_pos == base.len - 1) {
|
||||||
@@ -216,41 +220,41 @@ test "URL: resolve size" {
|
|||||||
test "URL: Stitching Base & Src URLs (Basic)" {
|
test "URL: Stitching Base & Src URLs (Basic)" {
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
const base = "https://www.google.com/xyz/abc/123";
|
const base = "https://lightpanda.io/xyz/abc/123";
|
||||||
const src = "something.js";
|
const src = "something.js";
|
||||||
const result = try URL.stitch(allocator, src, base, .{});
|
const result = try URL.stitch(allocator, src, base, .{});
|
||||||
defer allocator.free(result);
|
defer allocator.free(result);
|
||||||
try testing.expectString("https://www.google.com/xyz/abc/something.js", result);
|
try testing.expectString("https://lightpanda.io/xyz/abc/something.js", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "URL: Stitching Base & Src URLs (Just Ending Slash)" {
|
test "URL: Stitching Base & Src URLs (Just Ending Slash)" {
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
const base = "https://www.google.com/";
|
const base = "https://lightpanda.io/";
|
||||||
const src = "something.js";
|
const src = "something.js";
|
||||||
const result = try URL.stitch(allocator, src, base, .{});
|
const result = try URL.stitch(allocator, src, base, .{});
|
||||||
defer allocator.free(result);
|
defer allocator.free(result);
|
||||||
try testing.expectString("https://www.google.com/something.js", result);
|
try testing.expectString("https://lightpanda.io/something.js", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "URL: Stitching Base & Src URLs with leading slash" {
|
test "URL: Stitching Base & Src URLs with leading slash" {
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
const base = "https://www.google.com/";
|
const base = "https://lightpanda.io/";
|
||||||
const src = "/something.js";
|
const src = "/something.js";
|
||||||
const result = try URL.stitch(allocator, src, base, .{});
|
const result = try URL.stitch(allocator, src, base, .{});
|
||||||
defer allocator.free(result);
|
defer allocator.free(result);
|
||||||
try testing.expectString("https://www.google.com/something.js", result);
|
try testing.expectString("https://lightpanda.io/something.js", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "URL: Stitching Base & Src URLs (No Ending Slash)" {
|
test "URL: Stitching Base & Src URLs (No Ending Slash)" {
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
const base = "https://www.google.com";
|
const base = "https://lightpanda.io";
|
||||||
const src = "something.js";
|
const src = "something.js";
|
||||||
const result = try URL.stitch(allocator, src, base, .{});
|
const result = try URL.stitch(allocator, src, base, .{});
|
||||||
defer allocator.free(result);
|
defer allocator.free(result);
|
||||||
try testing.expectString("https://www.google.com/something.js", result);
|
try testing.expectString("https://lightpanda.io/something.js", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "URL: Stiching Base & Src URLs (Both Local)" {
|
test "URL: Stiching Base & Src URLs (Both Local)" {
|
||||||
@@ -275,11 +279,21 @@ test "URL: Stiching src as full path" {
|
|||||||
test "URL: Stitching Base & Src URLs (empty src)" {
|
test "URL: Stitching Base & Src URLs (empty src)" {
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
const base = "https://www.google.com/xyz/abc/123";
|
const base = "https://lightpanda.io/xyz/abc/123";
|
||||||
const src = "";
|
const src = "";
|
||||||
const result = try URL.stitch(allocator, src, base, .{});
|
const result = try URL.stitch(allocator, src, base, .{});
|
||||||
defer allocator.free(result);
|
defer allocator.free(result);
|
||||||
try testing.expectString("https://www.google.com/xyz/abc/123", result);
|
try testing.expectString("https://lightpanda.io/xyz/abc/123", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "URL: Stitching dotslash" {
|
||||||
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
|
const base = "https://lightpanda.io/hello/";
|
||||||
|
const src = "./something.js";
|
||||||
|
const result = try URL.stitch(allocator, src, base, .{});
|
||||||
|
defer allocator.free(result);
|
||||||
|
try testing.expectString("https://lightpanda.io/hello/something.js", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "URL: concatQueryString" {
|
test "URL: concatQueryString" {
|
||||||
|
|||||||
Reference in New Issue
Block a user