Skip to content
Snippets Groups Projects
Commit 01b3193f authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Parser.XML.Tree: Fixed handling of namespaced attributes some more.

Also adds some more tests.

COMPAT WARNING:
  Attribute namespaces starting with "xml" (except for "xmlns")
  are now handled just like any other attribute namespaces. This
  means that eg the attribute "xml:lang" will be expanded to
  "http://www.w3.org/XML/1998/namespacelang" in the mapping
  returned by get_attributes(), and not kept as "xml:lang" when
  namespace handling is enabled.
parent 6c4b9b71
Branches
Tags
No related merge requests found
......@@ -244,7 +244,7 @@ class XMLNSParser {
key = name[..i-1];
name = name[i+1..];
}
if (has_prefix(key||"", "xml") || (name == "xmlns")) {
if ((key || name) == "xmlns") {
if (key) name = key + ":" + name;
return name;
}
......
......@@ -114,28 +114,45 @@ test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
// Test of implicit xml: namespace.
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob)
// Test InfoKOM 803815.
test_do([[add_constant("xmlblob", #"<?xml version='1.0' encoding='UTF-8'?><foo xmlns='http://bar.com/test' xmlns:bar='http://foo.com/bar/'>
<hej bar:gazonk='hopp' xml:lang='sv-SE'>
<tag>test</tag>
</hej>
</foo>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob)
// Test of explicit xml: namespace.
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xml='http://www.w3.org/XML/1998/namespace'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES)->render_xml()]], xmlblob)
// Test detection of invalid namespaces.
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xml='http://www.w3.org/XML/1998/invalid'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]])
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:invalid='http://www.w3.org/XML/1998/namespace'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]])
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xmlns='http://www.w3.org/2000/xmlns/'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]])
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:xmlns='http://www.w3.org/2000/invalid/'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]])
test_do([[add_constant("xmlblob", "<?xml version='1.0' encoding='utf-8'?><foo xml:lang='bar' xmlns='gazonk:' xmlns:invalid='http://www.w3.org/2000/xmlns/'/>");]])
test_eq([[Parser.XML.Tree.simple_parse_input(xmlblob)->render_xml()]], xmlblob)
test_eval_error([[Parser.XML.Tree.simple_parse_input(xmlblob, UNDEFINED,
Parser.XML.Tree.PARSE_ENABLE_NAMESPACES);]])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment