Fix checksum hash attribute insertion for self-closing root tags. Fixes #4323

This commit is contained in:
Jim
2015-07-09 12:10:48 -07:00
parent a9e2111b34
commit dfeeb3f673
2 changed files with 14 additions and 2 deletions
@@ -22,9 +22,11 @@ var ReactMarkupChecksum = {
*/
addChecksumToMarkup: function(markup) {
var checksum = adler32(markup);
// Add checksum (handle both parent tags and self-closing tags)
return markup.replace(
'>',
' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '">'
/\/?>/,
' ' + ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="' + checksum + '"$&'
);
},
@@ -57,6 +57,16 @@ describe('ReactServerRendering', function() {
);
});
it('should generate simple markup for self-closing tags', function() {
var response = ReactServerRendering.renderToString(
<img />
);
expect(response).toMatch(
'<img ' + ID_ATTRIBUTE_NAME + '="[^"]+" ' +
ReactMarkupChecksum.CHECKSUM_ATTR_NAME + '="[^"]+"/>'
);
});
it('should not register event listeners', function() {
var EventPluginHub = require('EventPluginHub');
var cb = mocks.getMockFunction();