diff --git a/src/browser/tests/document/create_element_ns.html b/src/browser/tests/document/create_element_ns.html index c14a2773..46773ebc 100644 --- a/src/browser/tests/document/create_element_ns.html +++ b/src/browser/tests/document/create_element_ns.html @@ -28,5 +28,13 @@ const regularDiv = document.createElement('div'); testing.expectEqual('DIV', regularDiv.tagName); + testing.expectEqual('div', regularDiv.localName); + testing.expectEqual(null, regularDiv.prefix); testing.expectEqual('http://www.w3.org/1999/xhtml', regularDiv.namespaceURI); + + const custom = document.createElementNS('test', 'te:ST'); + testing.expectEqual('te:ST', custom.tagName); + testing.expectEqual('te', custom.prefix); + testing.expectEqual('ST', custom.localName); + testing.expectEqual('http://www.w3.org/1999/xhtml', custom.namespaceURI); // Should be test diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zig index 36215d47..595d25fd 100644 --- a/src/browser/webapi/Element.zig +++ b/src/browser/webapi/Element.zig @@ -769,7 +769,15 @@ fn upperTagName(tag_name: *String, buf: []u8) []const u8 { log.info(.dom, "tag.long.name", .{ .name = tag_name.str() }); return tag_name.str(); } - return std.ascii.upperString(buf, tag_name.str()); + const tag = tag_name.str(); + // If the tag_name has a prefix, we must uppercase only the suffix part. + // example: te:st should be returned as te:ST. + if (std.mem.indexOfPos(u8, tag, 0, ":")) |pos| { + @memcpy(buf[0 .. pos + 1], tag[0 .. pos + 1]); + _ = std.ascii.upperString(buf[pos..tag.len], tag[pos..tag.len]); + return buf[0..tag.len]; + } + return std.ascii.upperString(buf, tag); } pub fn getTag(self: *const Element) Tag { @@ -917,6 +925,26 @@ pub const JsApi = struct { return buf.written(); } + pub const prefix = bridge.accessor(_prefix, null, .{}); + fn _prefix(self: *Element) ?[]const u8 { + const name = self.getTagNameLower(); + if (std.mem.indexOfPos(u8, name, 0, ":")) |pos| { + return name[0..pos]; + } + + return null; + } + + pub const localName = bridge.accessor(_localName, null, .{}); + fn _localName(self: *Element) []const u8 { + const name = self.getTagNameLower(); + if (std.mem.indexOfPos(u8, name, 0, ":")) |pos| { + return name[pos + 1 ..]; + } + + return name; + } + pub const id = bridge.accessor(Element.getId, Element.setId, .{}); pub const className = bridge.accessor(Element.getClassName, Element.setClassName, .{}); pub const classList = bridge.accessor(Element.getClassList, null, .{});