diff --git a/src/dom/document.zig b/src/dom/document.zig index a2dfe3c8..5a4e496d 100644 --- a/src/dom/document.zig +++ b/src/dom/document.zig @@ -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" }, diff --git a/src/dom/html_collection.zig b/src/dom/html_collection.zig index 9dfb3b94..b96d7bec 100644 --- a/src/dom/html_collection.zig +++ b/src/dom/html_collection.zig @@ -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.