Skip to content

Commit

Permalink
Fixes #3: The reserved xml prefix may be used without pre-declaring…
Browse files Browse the repository at this point in the history
… it.
  • Loading branch information
Gavin Kistner committed Feb 12, 2014
1 parent cdcce0e commit 7e59290
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion slaxml.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[=====================================================================[
v0.5.2 Copyright © 2013 Gavin Kistner <!@phrogz.net>; MIT Licensed
v0.5.3 Copyright © 2013 Gavin Kistner <!@phrogz.net>; MIT Licensed
See http://github.com/Phrogz/SLAXML for details.
--]=====================================================================]
local SLAXML = {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/files/xml_namespace.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion test/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +125,16 @@ function test_dom_entities()
assertEqual(t.kids[6].value,' your code &gt; 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/"
Expand Down

0 comments on commit 7e59290

Please sign in to comment.