106
checkId(node.childNodes[2].firstChild, '.r[0].[0:2].[0:chipmunk]');
107
});
108
109
+ function renderAComponentWithKeyIntoContainer(key, container) {
110
+ var span1 = <span key={key} />;
111
+ var span2 = <span />;
112
+
113
+ var map = {};
114
+ map[key] = span2;
115
+
116
+ React.renderComponent(<div>{[span1, map]}</div>, container);
117
+
118
+ expect(span1.getDOMNode()).not.toBe(null);
119
+ expect(span2.getDOMNode()).not.toBe(null);
120
+
121
+ checkId(span1.getDOMNode(), '.r[0].[0:0:' + key + ']');
122
+ checkId(span2.getDOMNode(), '.r[0].[1]{' + key + '}');
123
+ }
124
+
125
+ it('should allow any character as a key, in a detached parent', function() {
126
+ var detachedContainer = document.createElement('div');
127
+ renderAComponentWithKeyIntoContainer("<'WEIRD/&\\key'>", detachedContainer);
128
+ });
129
+
130
+ it('should allow any character as a key, in an attached parent', function() {
131
+ // This test exists to protect against implementation details that
132
+ // incorrectly query escaped IDs using DOM tools like getElementById.
133
+ var attachedContainer = document.createElement('div');
134
+ document.body.appendChild(attachedContainer);
135
+
136
+ renderAComponentWithKeyIntoContainer("<'WEIRD/&\\key'>", attachedContainer);
137
+
138
+ document.body.removeChild(attachedContainer);
139
+ });
140
+
141
+ it('should not allow scripts in keys to execute', function() {
142
+ var h4x0rKey = '"><script>window.YOUVEBEENH4X0RED=true;</script><div id="';
143
+
144
+ var attachedContainer = document.createElement('div');
145
+ document.body.appendChild(attachedContainer);
146
+
147
+ renderAComponentWithKeyIntoContainer(h4x0rKey, attachedContainer);
148
+
149
+ document.body.removeChild(attachedContainer);
150
+
151
+ // If we get this far, make sure we haven't executed the code
152
+ expect(window.YOUVEBEENH4X0RED).toBe(undefined);
153
+ });
154
+
155
it('should let restructured components retain their uniqueness', function() {
156
var instance0 = <span />;
157
var instance1 = <span />;