Skip to content

Commit

Permalink
Fix d3#2722 - case-sensitivity of selection.append.
Browse files Browse the repository at this point in the history
If the implicit namespace of the created element matches that of the document
element, the document’s createElement should be used instead of createElementNS.
This way, in documents for which createElement is case-insensitive—most notably
HTML documents—selection.append is likewise case-insensitive.
  • Loading branch information
mbostock committed Jan 27, 2016
1 parent f749f70 commit 05fd32d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"animation",
"canvas"
],
"version": "3.5.13",
"version": "3.5.14",
"main": "d3.js",
"scripts": [
"d3.js"
Expand Down
4 changes: 2 additions & 2 deletions d3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!function() {
var d3 = {
version: "3.5.13"
version: "3.5.14"
};
var d3_arraySlice = [].slice, d3_array = function(list) {
return d3_arraySlice.call(list);
Expand Down Expand Up @@ -805,7 +805,7 @@
function d3_selection_creator(name) {
function create() {
var document = this.ownerDocument, namespace = this.namespaceURI;
return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
return namespace && namespace !== document.documentElement.namespaceURI ? document.createElementNS(namespace, name) : document.createElement(name);
}
function createNS() {
return this.ownerDocument.createElementNS(name.space, name.local);
Expand Down
10 changes: 5 additions & 5 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Package.describe({
name: "d3js:d3", // http://atmospherejs.com/d3js/d3
summary: "D3 (official): A JavaScript visualization library for HTML and SVG.",
version: "3.5.13",
version: "3.5.14",
git: "https://github.com/mbostock/d3.git"
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.5.13",
"version": "3.5.14",
"description": "A JavaScript visualization library for HTML and SVG.",
"keywords": [
"dom",
Expand Down
2 changes: 1 addition & 1 deletion src/selection/append.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function d3_selection_creator(name) {
function create() {
var document = this.ownerDocument,
namespace = this.namespaceURI;
return namespace
return namespace && namespace !== document.documentElement.namespaceURI
? document.createElementNS(namespace, name)
: document.createElement(name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
!function(){
var d3 = {version: "3.5.13"}; // semver
var d3 = {version: "3.5.14"}; // semver
31 changes: 31 additions & 0 deletions test/selection/append-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,37 @@ suite.addBatch({
"inherits namespace from parent node": function(body) {
var g = body.append("svg:svg").append("g");
assert.equal(g[0][0].namespaceURI, "http://www.w3.org/2000/svg");
},
"uses createElement when the implicit namespace matches the document": function(body) {
var document = body.node().ownerDocument, createElement = document.createElement, pass = 0;
document.createElement = function() { ++pass; return createElement.apply(this, arguments); };
try {
body.append("p");
} finally {
document.createElement = createElement;
}
assert.equal(pass, 1);
},
"uses createElementNS when the implicit namespace does not match the document": function(body) {
var document = body.node().ownerDocument, createElementNS = document.createElementNS, pass = 0;
document.createElementNS = function() { ++pass; return createElementNS.apply(this, arguments); };
try {
body.append("svg").append("g");
} finally {
document.createElementNS = createElementNS;
}
assert.equal(pass, 2);
},
"uses createElementNS when given an explicit namespace": function(body) {
var document = body.node().ownerDocument, createElementNS = document.createElementNS, pass = 0;
document.createElementNS = function() { ++pass; return createElementNS.apply(this, arguments); };
try {
body.append("svg:svg");
body.append("xhtml:p");
} finally {
document.createElementNS = createElementNS;
}
assert.equal(pass, 2);
}
}
}
Expand Down

0 comments on commit 05fd32d

Please sign in to comment.