Skip to content

Commit a434793

Browse files
authored
Ensure XML.attributes(node) === nothing when node has no attributes
Speculative suggestion. Tests pass locally but I think this needs deeper understanding than I can bring.
1 parent ff0ee25 commit a434793

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/XML.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ Node(data::Raw) = Node(LazyNode(data))
171171
# Anything that's not Vector{UInt8} or a (Lazy)Node is converted to a Text Node
172172
Node(x) = Node(Text, nothing, nothing, string(x), nothing)
173173

174-
h(tag::Union{Symbol, String}, children...; kw...) = Node(Element, tag, kw, nothing, children)
174+
h(tag::Union{Symbol, String}, children...; kw...) = Node(Element, tag, length(kw)==0 ? nothing : kw, nothing, children)
175+
# h(tag::Union{Symbol, String}, children...; kw...) = Node(Element, tag, kw, nothing, children)
175176
Base.getproperty(::typeof(h), tag::Symbol) = h(tag)
176177
(o::Node)(children...; kw...) = Node(o, Node.(children)...; kw...)
177178

@@ -240,7 +241,8 @@ function (T::NodeType)(args...; attr...)
240241
Node(T, nothing, nothing, only(args))
241242
elseif T === Element
242243
tag = first(args)
243-
Node(T, tag, attr, nothing, args[2:end])
244+
Node(T, tag, length(attr)==0 ? nothing : attr, nothing, args[2:end])
245+
# Node(T, tag, attr, nothing, args[2:end])
244246
else
245247
error("Unreachable reached while trying to create a Node via (::NodeType)(args...; kw...).")
246248
end

0 commit comments

Comments
 (0)