mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-04-01 18:06:46 +00:00
fix(browser-url): handle specific file scheme and change error InvalidURL to TypeError
This commit is contained in:
@@ -58,12 +58,12 @@ pub fn resolve(allocator: Allocator, base: [:0]const u8, source_path: anytype, c
|
|||||||
while (rest_start < path.len and (path[rest_start] == '/' or path[rest_start] == '\\')) {
|
while (rest_start < path.len and (path[rest_start] == '/' or path[rest_start] == '\\')) {
|
||||||
rest_start += 1;
|
rest_start += 1;
|
||||||
}
|
}
|
||||||
//special scheme need to any symbols after "://"
|
// A special scheme (exclude "file") must contain at least anu chars after "://"
|
||||||
if (rest_start >= path.len) {
|
if (rest_start == path.len and !std.ascii.eqlIgnoreCase(scheme_path, "file")) {
|
||||||
return error.InvalidURL;
|
return error.TypeError;
|
||||||
}
|
}
|
||||||
//File scheme allow empty host
|
//File scheme allow empty host
|
||||||
const separator: []const u8 = if (std.ascii.eqlIgnoreCase(scheme_path, "file") and !has_double_slashas) ":///" else "://";
|
const separator: []const u8 = if (!has_double_slashas and std.ascii.eqlIgnoreCase(scheme_path, "file")) ":///" else "://";
|
||||||
|
|
||||||
path = try std.mem.joinZ(allocator, "", &.{ scheme_path, separator, path[rest_start..] });
|
path = try std.mem.joinZ(allocator, "", &.{ scheme_path, separator, path[rest_start..] });
|
||||||
return processResolved(allocator, path, opts);
|
return processResolved(allocator, path, opts);
|
||||||
@@ -1694,6 +1694,12 @@ test "URL: resolve path scheme" {
|
|||||||
.path = "file:/path/to/file",
|
.path = "file:/path/to/file",
|
||||||
.expected = "file:///path/to/file",
|
.expected = "file:///path/to/file",
|
||||||
},
|
},
|
||||||
|
//different schemes and path as absolute (path scheme=file, host is empty)
|
||||||
|
.{
|
||||||
|
.base = "https://www.example.com/example",
|
||||||
|
.path = "file:/",
|
||||||
|
.expected = "file:///",
|
||||||
|
},
|
||||||
//different schemes without :// and normalize "file" scheme, absolute path
|
//different schemes without :// and normalize "file" scheme, absolute path
|
||||||
.{
|
.{
|
||||||
.base = "https://www.example.com/example",
|
.base = "https://www.example.com/example",
|
||||||
@@ -1770,15 +1776,12 @@ test "URL: resolve path scheme" {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (cases) |case| {
|
for (cases) |case| {
|
||||||
const result = resolve(testing.arena_allocator, case.base, case.path, .{}) catch |err| {
|
if (case.expected_error) {
|
||||||
if (err == error.InvalidURL) {
|
const result = resolve(testing.arena_allocator, case.base, case.path, .{});
|
||||||
try testing.expect(case.expected_error);
|
try testing.expectError(error.TypeError, result);
|
||||||
continue;
|
} else {
|
||||||
}
|
const result = try resolve(testing.arena_allocator, case.base, case.path, .{});
|
||||||
|
|
||||||
return err;
|
|
||||||
};
|
|
||||||
|
|
||||||
try testing.expectString(case.expected, result);
|
try testing.expectString(case.expected, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -750,7 +750,6 @@ const CloneError = error{
|
|||||||
TypeError,
|
TypeError,
|
||||||
CompilationError,
|
CompilationError,
|
||||||
JsException,
|
JsException,
|
||||||
InvalidURL,
|
|
||||||
};
|
};
|
||||||
pub fn cloneNode(self: *Node, deep_: ?bool, page: *Page) CloneError!*Node {
|
pub fn cloneNode(self: *Node, deep_: ?bool, page: *Page) CloneError!*Node {
|
||||||
const deep = deep_ orelse false;
|
const deep = deep_ orelse false;
|
||||||
|
|||||||
Reference in New Issue
Block a user