From 8ec9f634b46b17a1dd1b4bcaeb0797a29f8aea5d Mon Sep 17 00:00:00 2001 From: Muki Kiboigo Date: Mon, 8 Dec 2025 05:16:45 -0800 Subject: [PATCH] backport URL eqlDocument tests --- src/browser/URL.zig | 71 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/src/browser/URL.zig b/src/browser/URL.zig index 6fdc97b9..11739b07 100644 --- a/src/browser/URL.zig +++ b/src/browser/URL.zig @@ -272,11 +272,12 @@ pub fn getHost(raw: [:0]const u8) []const u8 { // Returns true if these two URLs point to the same document. pub fn eqlDocument(first: [:0]const u8, second: [:0]const u8) bool { + if (!std.mem.eql(u8, getProtocol(first), getProtocol(second))) return false; if (!std.mem.eql(u8, getHost(first), getHost(second))) return false; if (!std.mem.eql(u8, getPort(first), getPort(second))) return false; if (!std.mem.eql(u8, getPathname(first), getPathname(second))) return false; if (!std.mem.eql(u8, getSearch(first), getSearch(second))) return false; - if (!std.mem.eql(u8, getHash(first), getHash(second))) return false; + // hashes are allowed to be different. return true; } @@ -449,3 +450,71 @@ test "URL: resolve" { try testing.expectString(case.expected, result); } } + +test "URL: eqlDocument" { + defer testing.reset(); + { + const url = "https://lightpanda.io/about"; + try testing.expectEqual(true, eqlDocument(url, url)); + } + { + const url1 = "https://lightpanda.io/about"; + const url2 = "http://lightpanda.io/about"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about"; + const url2 = "https://example.com/about"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io:8080/about"; + const url2 = "https://lightpanda.io:9090/about"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about"; + const url2 = "https://lightpanda.io/contact"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about?foo=bar"; + const url2 = "https://lightpanda.io/about?baz=qux"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about#section1"; + const url2 = "https://lightpanda.io/about#section2"; + try testing.expectEqual(true, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about"; + const url2 = "https://lightpanda.io/about/"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about?foo=bar"; + const url2 = "https://lightpanda.io/about"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about"; + const url2 = "https://lightpanda.io/about?foo=bar"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about?foo=bar"; + const url2 = "https://lightpanda.io/about?foo=bar"; + try testing.expectEqual(true, eqlDocument(url1, url2)); + } + { + const url1 = "https://lightpanda.io/about?"; + const url2 = "https://lightpanda.io/about"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } + { + const url1 = "https://duckduckgo.com/"; + const url2 = "https://duckduckgo.com/?q=lightpanda"; + try testing.expectEqual(false, eqlDocument(url1, url2)); + } +}