Permalink
Browse files

Don't apply default namespace to attributes.

  • Loading branch information...
mikeatemotive authored and isaacs committed May 18, 2012
1 parent 9a9e5fe commit 3cebba7aad07145116cd0063a7c5cfb639f50e9c
Showing with 35 additions and 3 deletions.
  1. +3 −1 lib/sax.js
  2. +2 −2 test/xmlns-strict.js
  3. +30 −0 test/xmlns-xml-default-ns.js
View
@@ -463,14 +463,16 @@ function openTag (parser, selfClosing) {
}
// handle deferred onattribute events
+ // Note: do not apply default ns to attributes:
+ // http://www.w3.org/TR/REC-xml-names/#defaulting
for (var i = 0, l = parser.attribList.length; i < l; i ++) {
var nv = parser.attribList[i]
var name = nv[0]
, value = nv[1]
, qualName = qname(name)
, prefix = qualName.prefix
, local = qualName.local
- , uri = tag.ns[prefix] || ""
+ , uri = prefix == "" ? "" : (tag.ns[prefix] || "")
, a = { name: name
, value: value
, prefix: prefix
View
@@ -29,9 +29,9 @@ require(__dirname).test
attributes: { "xmlns": { name: "xmlns", value: "uri:default", prefix: "xmlns", local: "", uri: "http://www.w3.org/2000/xmlns/" } },
ns: { "": "uri:default" } } ]
- , [ "attribute", { name: "attr", value: "normal", prefix: "", local: "attr", uri: "uri:default" } ]
+ , [ "attribute", { name: "attr", value: "normal", prefix: "", local: "attr", uri: "" } ]
, [ "opentag", { name: "plain", prefix: "", local: "plain", uri: "uri:default", ns: { '': 'uri:default' },
- attributes: { "attr": { name: "attr", value: "normal", prefix: "", local: "attr", uri: "uri:default" } } } ]
+ attributes: { "attr": { name: "attr", value: "normal", prefix: "", local: "attr", uri: "" } } } ]
, [ "closetag", "plain" ]
, [ "closetag", "ns1" ]
@@ -0,0 +1,30 @@
+var xmlns_attr =
+{
+ name: "xmlns", value: "http://foo", prefix: "xmlns",
+ local: "", uri : "http://www.w3.org/2000/xmlns/"
+};
+
+var attr_attr =
+{
+ name: "attr", value: "bar", prefix: "",
+ local : "attr", uri : ""
+};
+
+
+require(__dirname).test
+ ( { xml :
+ "<elm xmlns='http://foo' attr='bar'/>"
+ , expect :
+ [ [ "opennamespace", { prefix: "", uri: "http://foo" } ]
+ , [ "attribute", xmlns_attr ]
+ , [ "attribute", attr_attr ]
+ , [ "opentag", { name: "elm", prefix: "", local: "elm", uri : "http://foo",
+ ns : { "" : "http://foo" },
+ attributes: { xmlns: xmlns_attr, attr: attr_attr } } ]
+ , [ "closetag", "elm" ]
+ , [ "closenamespace", { prefix: "", uri: "http://foo"} ]
+ ]
+ , strict : true
+ , opt : {xmlns: true}
+ }
+ )

0 comments on commit 3cebba7

Please sign in to comment.