Skip to content

Error Serializing Inherited Attributes #1442

@deckar01

Description

@deckar01

Extending the Object.prototype causes Element.outerHTML() to break.

var jsdom = require('jsdom');

Object.prototype.test_name = 'test_value';

var dom = jsdom.jsdom('<div id="0"></div>');

var div = dom.getElementById('0');

console.log(div.test_name);
console.log(div.outerHTML);
test_value
<div id="0" test_value:test_name="test_value"></div>

This tells me that the issue is with the jsdom since its documentAdapter is being passed to the serializer.

I would expect jsdom to skip attributes inherited from Object.

Oddly if Object.prototype is extended after the DOM is initialized it works as expected.

var jsdom = require('jsdom');

var dom = jsdom.jsdom('<div id="0"></div>');

Object.prototype.test_name = 'test_value';

var div = dom.getElementById('0');

console.log(div.test_name);
console.log(div.outerHTML);
test_value
<div id="0"></div>

I suspect the HTMLElement inheritance tree affects the attributes when creating the div, but requires explicit calls through the DOM APIs to change, so the fix will likely be during the attributes initialization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions