From 7e59290887049cd8657c58972dfba5777116f799 Mon Sep 17 00:00:00 2001 From: Gavin Kistner Date: Wed, 12 Feb 2014 12:08:58 -0700 Subject: [PATCH] Fixes #3: The reserved `xml` prefix may be used without pre-declaring it. --- README.md | 5 +++++ slaxml.lua | 3 ++- test/files/xml_namespace.svg | 12 ++++++++++++ test/test.lua | 12 +++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/files/xml_namespace.svg diff --git a/README.md b/README.md index c03d9a5..87ed877 100644 --- a/README.md +++ b/README.md @@ -140,10 +140,15 @@ In this case no table will have a `parent` attribute, elements will not have the - No support for extended (Unicode) characters in element/attribute names - No support for charset - No support for [XInclude](http://www.w3.org/TR/xinclude/) +- Does not ensure that the reserved `xml` prefix is never redefined to an illegal namespace +- Does not ensure that the reserved `xmlns` prefix is never used as an element prefix ## History +### v0.5.3 2014-Feb-12 ++ Fixes Issue #3: The [reserved `xml` prefix](http://www.w3.org/TR/xml-names/#ns-decl) may be used without pre-declaring it. (Thanks David Durkee.) + ### v0.5.2 2013-Nov-7 + Lua 5.2 compatible + Parser now errors if it finishes without finding a root element, diff --git a/slaxml.lua b/slaxml.lua index 9462e9e..6021263 100644 --- a/slaxml.lua +++ b/slaxml.lua @@ -1,5 +1,5 @@ --[=====================================================================[ -v0.5.2 Copyright © 2013 Gavin Kistner ; MIT Licensed +v0.5.3 Copyright © 2013 Gavin Kistner ; MIT Licensed See http://github.com/Phrogz/SLAXML for details. --]=====================================================================] local SLAXML = { @@ -85,6 +85,7 @@ function SLAXML:parse(xml,options) end local function nsForPrefix(prefix) + if prefix=='xml' then return 'http://www.w3.org/XML/1998/namespace' end -- http://www.w3.org/TR/xml-names/#ns-decl for i=#nsStack,1,-1 do if nsStack[i][prefix] then return nsStack[i][prefix] end end error(("Cannot find namespace for prefix %s"):format(prefix)) end diff --git a/test/files/xml_namespace.svg b/test/files/xml_namespace.svg new file mode 100644 index 0000000..36e59aa --- /dev/null +++ b/test/files/xml_namespace.svg @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/test/test.lua b/test/test.lua index 15c60f0..af9fe49 100644 --- a/test/test.lua +++ b/test/test.lua @@ -4,7 +4,7 @@ local SLAXML = require 'slaxdom' require 'io' require 'lunity' -module( 'TEST_LXSC', lunity ) +module( 'TEST_SLAXML', lunity ) local XML = {} for filename in io.popen('ls files'):lines() do @@ -125,6 +125,16 @@ function test_dom_entities() assertEqual(t.kids[6].value,' your code > all ') end +function test_xml_namespace() + local doc = SLAXML:dom(XML['xml_namespace']) + for i,attr in ipairs(doc.root.attr) do + if attr.name=='space' then + assertEqual(attr.nsURI,[[http://www.w3.org/XML/1998/namespace]]) + break + end + end +end + function test_dom_namespaces() local scxmlNS = "http://www.w3.org/2005/07/scxml" local phrogzNS = "http://phrogz.net/"