mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-23 22:58:00 -05:00
set page base_url during HTML parsing
This commit is contained in:
@@ -1430,6 +1430,24 @@ pub fn createElement(self: *Page, ns_: ?[]const u8, name: []const u8, attribute_
|
||||
attribute_iterator,
|
||||
.{ ._proto = undefined },
|
||||
),
|
||||
asUint("base") => {
|
||||
const n = try self.createHtmlElementT(
|
||||
Element.Html.Generic,
|
||||
namespace,
|
||||
attribute_iterator,
|
||||
.{ ._proto = undefined, ._tag_name = String.init(undefined, "base", .{}) catch unreachable, ._tag = .base },
|
||||
);
|
||||
|
||||
// If page's base url is not already set, fill it with the base
|
||||
// tag.
|
||||
if (self.base_url == null) {
|
||||
if (n.as(Element).getAttributeSafe("href")) |href| {
|
||||
self.base_url = try URL.resolve(self.arena, self.url, href, .{});
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
},
|
||||
else => {},
|
||||
},
|
||||
5 => switch (@as(u40, @bitCast(name[0..5].*))) {
|
||||
|
||||
14
src/browser/tests/node/base_uri.html
Normal file
14
src/browser/tests/node/base_uri.html
Normal file
@@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../testing.js"></script>
|
||||
<base href="https://example.com/">
|
||||
|
||||
<a href="foo" id="foo">foo</a>
|
||||
|
||||
<script id=baseURI>
|
||||
testing.expectEqual("http://127.0.0.1:9582/src/browser/tests/node/base_uri.html", document.URL);
|
||||
testing.expectEqual("https://example.com/", document.baseURI);
|
||||
|
||||
const link = $('#foo');
|
||||
testing.expectEqual("https://example.com/foo", link.href);
|
||||
</script>
|
||||
|
||||
@@ -1178,6 +1178,7 @@ pub const Tag = enum {
|
||||
body,
|
||||
br,
|
||||
button,
|
||||
base,
|
||||
canvas,
|
||||
circle,
|
||||
custom,
|
||||
|
||||
Reference in New Issue
Block a user