Reset default NS test and partial fix#7
Reset default NS test and partial fix#7hanshuebner wants to merge 2 commits intolunarmodules:mainfrom
Conversation
This ensures that the default namespace can be reset in documents.
|
slack discussion: @hanshuebner local expadom = require "expadom"
local xml = [[
<foo xmlns="http://example.com/">
<bar xmlns="">
<baz/>
</bar>
</foo>
]]
local doc = assert(expadom.parseDocument(xml))
print(xml)
print(table.concat(doc:write()))The output is <?xml version="1.0" encoding="UTF-8" ?>
<foo xmlns="http://example.com/">
<bar>
<baz/>
</bar>
</foo>expadom incorrectly renders the bar element to be in the http://example.com/ namespace even though the default namespace has been reset on that element in the input file. This breaks some of the c14n test cases so it needs to be fixed. Maybe you can guide me on this or you can quickly determine the cause for the misbehavior? I think it is not a LuaExapat problem as the element is correctly passed to StartElement without a namespace: StartElement = function(parser, elementName, attributes)
local ctx = context_cache[parser]
local doc = ctx.doc
local qualifiedName, namespaceURI = split(elementName)
-- attach defined explicit namespaces on this element
local explicitNamespaces = ctx.explicitNamespaces
ctx.explicitNamespaces = {}
local elem
if namespaceURI then
elem = assert(doc:createElementNS(namespaceURI, qualifiedName))
local prefix = elem.__prop_values.prefix
explicitNamespaces[prefix or DEFAULT_NS_KEY] = nil -- remove since it's implicit
else
elem = assert(doc:createElement(qualifiedName))
endIt seems that if no namespace is attached to the element, the current namespace is used by the way of the context? But I'm not sure. Any ideas? @Tieske @hanshuebner Maybe this? StartElement = function(parser, elementName, attributes)
local ctx = context_cache[parser]
local doc = ctx.doc
local qualifiedName, namespaceURI = split(elementName)
-- attach defined explicit namespaces on this element
local explicitNamespaces = ctx.explicitNamespaces
ctx.explicitNamespaces = {}
local elem
elem = assert(doc:createElementNS(namespaceURI or "", qualifiedName))
local prefix = elem.__prop_values.prefix
explicitNamespaces[prefix or DEFAULT_NS_KEY] = nil -- remove since it's impliciti.e. never use createElement ? It breaks a lot of tests though because it then incorrectly renders xmlns="" into every top-level element that does not have an explicit namespace defined. @Tieske |
As discussed on Slack