mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
dom: compare tagname in case insensitive way
This commit is contained in:
@@ -48,7 +48,6 @@ pub const Document = struct {
|
||||
const root = parser.documentGetDocumentNode(self);
|
||||
return HTMLCollection{
|
||||
.root = root,
|
||||
// TODO handle case insensitive comparison.
|
||||
.match = tag_name,
|
||||
};
|
||||
}
|
||||
@@ -77,7 +76,7 @@ pub fn testExecFn(
|
||||
try checkCases(js_env, &getElementById);
|
||||
|
||||
var getElementsByTagName = [_]Case{
|
||||
.{ .src = "let getElementsByTagName = document.getElementsByTagName('P')", .ex = "undefined" },
|
||||
.{ .src = "let getElementsByTagName = document.getElementsByTagName('p')", .ex = "undefined" },
|
||||
.{ .src = "getElementsByTagName.length", .ex = "2" },
|
||||
.{ .src = "getElementsByTagName.item(0).localName", .ex = "p" },
|
||||
.{ .src = "getElementsByTagName.item(1).localName", .ex = "p" },
|
||||
|
||||
@@ -4,6 +4,7 @@ const parser = @import("../netsurf.zig");
|
||||
|
||||
const jsruntime = @import("jsruntime");
|
||||
|
||||
const utils = @import("utils.z");
|
||||
const Element = @import("element.zig").Element;
|
||||
|
||||
// WEB IDL https://dom.spec.whatwg.org/#htmlcollection
|
||||
@@ -15,7 +16,7 @@ pub const HTMLCollection = struct {
|
||||
|
||||
root: *parser.Node,
|
||||
// match is used to select node against their name.
|
||||
// match comparison is case sensitive.
|
||||
// match comparison is case insensitive.
|
||||
match: []const u8,
|
||||
|
||||
/// _get_length computes the collection's length dynamically according to
|
||||
@@ -26,12 +27,15 @@ pub const HTMLCollection = struct {
|
||||
var node: ?*parser.Node = self.root;
|
||||
var ntype: parser.NodeType = undefined;
|
||||
|
||||
var buffer: [128]u8 = undefined;
|
||||
const imatch = std.ascii.upperString(&buffer, self.match);
|
||||
|
||||
var is_wildcard = std.mem.eql(u8, self.match, "*");
|
||||
|
||||
while (node != null) {
|
||||
ntype = parser.nodeType(node.?);
|
||||
if (ntype == .element) {
|
||||
if (is_wildcard or std.mem.eql(u8, self.match, parser.nodeName(node.?))) {
|
||||
if (is_wildcard or std.mem.eql(u8, imatch, parser.nodeName(node.?))) {
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
@@ -75,10 +79,13 @@ pub const HTMLCollection = struct {
|
||||
|
||||
var is_wildcard = std.mem.eql(u8, self.match, "*");
|
||||
|
||||
var buffer: [128]u8 = undefined;
|
||||
const imatch = std.ascii.upperString(&buffer, self.match);
|
||||
|
||||
while (node != null) {
|
||||
ntype = parser.nodeType(node.?);
|
||||
if (ntype == .element) {
|
||||
if (is_wildcard or std.mem.eql(u8, self.match, parser.nodeName(node.?))) {
|
||||
if (is_wildcard or std.mem.eql(u8, imatch, parser.nodeName(node.?))) {
|
||||
len += 1;
|
||||
|
||||
// check if we found the searched element.
|
||||
|
||||
Reference in New Issue
Block a user