File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -160,8 +160,14 @@ pub const Element = struct {
160160 }
161161 }
162162
163+ // don't use parser.nodeHasAttributes(...) because that returns true/false
164+ // based on the type, e.g. a node never as attributes, an element always has
165+ // attributes. But, Element.hasAttributes is supposed to return true only
166+ // if the element has at least 1 attribute.
163167 pub fn _hasAttributes (self : * parser.Element ) ! bool {
164- return try parser .nodeHasAttributes (parser .elementToNode (self ));
168+ // an element _must_ have at least an empty attribute
169+ const node_map = try parser .nodeGetAttributes (parser .elementToNode (self )) orelse unreachable ;
170+ return try parser .namedNodeMapGetLength (node_map ) > 0 ;
165171 }
166172
167173 pub fn _getAttribute (self : * parser.Element , qname : []const u8 ) ! ? []const u8 {
@@ -679,4 +685,8 @@ test "Browser.DOM.Element" {
679685 .{ "div1.innerHTML = \" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>\" " , null },
680686 .{ "div1.getElementsByTagName('a').length" , "1" },
681687 }, .{});
688+
689+ try runner .testCases (&.{
690+ .{ "document.createElement('a').hasAttributes()" , "false" },
691+ }, .{});
682692}
You can’t perform that action at this time.
0 commit comments