Skip to content

Commit 05fd32d

Browse files
committed
Fix d3#2722 - case-sensitivity of selection.append.
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.
1 parent f749f70 commit 05fd32d

8 files changed

Lines changed: 43 additions & 12 deletions

File tree

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"animation",
1111
"canvas"
1212
],
13-
"version": "3.5.13",
13+
"version": "3.5.14",
1414
"main": "d3.js",
1515
"scripts": [
1616
"d3.js"

d3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
!function() {
22
var d3 = {
3-
version: "3.5.13"
3+
version: "3.5.14"
44
};
55
var d3_arraySlice = [].slice, d3_array = function(list) {
66
return d3_arraySlice.call(list);
@@ -805,7 +805,7 @@
805805
function d3_selection_creator(name) {
806806
function create() {
807807
var document = this.ownerDocument, namespace = this.namespaceURI;
808-
return namespace ? document.createElementNS(namespace, name) : document.createElement(name);
808+
return namespace && namespace !== document.documentElement.namespaceURI ? document.createElementNS(namespace, name) : document.createElement(name);
809809
}
810810
function createNS() {
811811
return this.ownerDocument.createElementNS(name.space, name.local);

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Package.describe({
44
name: "d3js:d3", // http://atmospherejs.com/d3js/d3
55
summary: "D3 (official): A JavaScript visualization library for HTML and SVG.",
6-
version: "3.5.13",
6+
version: "3.5.14",
77
git: "https://github.com/mbostock/d3.git"
88
});
99

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "3.5.13",
3+
"version": "3.5.14",
44
"description": "A JavaScript visualization library for HTML and SVG.",
55
"keywords": [
66
"dom",

src/selection/append.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function d3_selection_creator(name) {
1313
function create() {
1414
var document = this.ownerDocument,
1515
namespace = this.namespaceURI;
16-
return namespace
16+
return namespace && namespace !== document.documentElement.namespaceURI
1717
? document.createElementNS(namespace, name)
1818
: document.createElement(name);
1919
}

src/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
!function(){
2-
var d3 = {version: "3.5.13"}; // semver
2+
var d3 = {version: "3.5.14"}; // semver

test/selection/append-test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,37 @@ suite.addBatch({
4141
"inherits namespace from parent node": function(body) {
4242
var g = body.append("svg:svg").append("g");
4343
assert.equal(g[0][0].namespaceURI, "http://www.w3.org/2000/svg");
44+
},
45+
"uses createElement when the implicit namespace matches the document": function(body) {
46+
var document = body.node().ownerDocument, createElement = document.createElement, pass = 0;
47+
document.createElement = function() { ++pass; return createElement.apply(this, arguments); };
48+
try {
49+
body.append("p");
50+
} finally {
51+
document.createElement = createElement;
52+
}
53+
assert.equal(pass, 1);
54+
},
55+
"uses createElementNS when the implicit namespace does not match the document": function(body) {
56+
var document = body.node().ownerDocument, createElementNS = document.createElementNS, pass = 0;
57+
document.createElementNS = function() { ++pass; return createElementNS.apply(this, arguments); };
58+
try {
59+
body.append("svg").append("g");
60+
} finally {
61+
document.createElementNS = createElementNS;
62+
}
63+
assert.equal(pass, 2);
64+
},
65+
"uses createElementNS when given an explicit namespace": function(body) {
66+
var document = body.node().ownerDocument, createElementNS = document.createElementNS, pass = 0;
67+
document.createElementNS = function() { ++pass; return createElementNS.apply(this, arguments); };
68+
try {
69+
body.append("svg:svg");
70+
body.append("xhtml:p");
71+
} finally {
72+
document.createElementNS = createElementNS;
73+
}
74+
assert.equal(pass, 2);
4475
}
4576
}
4677
}

0 commit comments

Comments
 (0)