mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-28 07:25:37 -04:00
use URL.isSameOrigin in Frame.isSameOrigin
This commit is contained in:
2 files changed
+3
-11
No files matched your search
@@ -638,15 +638,7 @@ pub fn getPinnedArena(self: *Frame, size_or_bucket: anytype, debug: []const u8)
|
||||
|
||||
pub fn isSameOrigin(self: *const Frame, url: [:0]const u8) bool {
|
||||
const current_origin = self.origin orelse return false;
|
||||
|
||||
// fastpath
|
||||
if (!std.mem.startsWith(u8, url, current_origin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Starting here, at least protocols are equals.
|
||||
// Compare hosts (domain:port) strictly
|
||||
return std.mem.eql(u8, URL.getHost(url), URL.getHost(current_origin));
|
||||
return URL.isSameOrigin(url, current_origin);
|
||||
}
|
||||
|
||||
pub fn navigate(self: *Frame, request_url: [:0]const u8, opts: NavigateOpts) !void {
|
||||
|
||||
+2
-2
@@ -215,7 +215,7 @@ pub fn getPathname(raw: [:0]const u8) []const u8 {
|
||||
return raw[path_start..query_or_hash_start];
|
||||
}
|
||||
|
||||
pub fn getProtocol(raw: [:0]const u8) []const u8 {
|
||||
pub fn getProtocol(raw: []const u8) []const u8 {
|
||||
const pos = std.mem.indexOfScalarPos(u8, raw, 0, ':') orelse return "";
|
||||
return raw[0 .. pos + 1];
|
||||
}
|
||||
@@ -341,7 +341,7 @@ pub fn getOrigin(allocator: Allocator, raw: [:0]const u8) !?[]const u8 {
|
||||
return raw[0..authority_end];
|
||||
}
|
||||
|
||||
pub fn isSameOrigin(url: [:0]const u8, origin: [:0]const u8) bool {
|
||||
pub fn isSameOrigin(url: []const u8, origin: []const u8) bool {
|
||||
return std.mem.eql(u8, getProtocol(url), getProtocol(origin)) and
|
||||
std.mem.eql(u8, getHost(url), getHost(origin));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user