Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing an element style property creates an empty style attribute when serialized #1109

Closed
n1k0 opened this issue Apr 28, 2015 · 2 comments
Labels

Comments

@n1k0
Copy link

n1k0 commented Apr 28, 2015

Using either 3.x (on node) or latest 5.1 (on iojs):

> jsdom = require("jsdom")
> doc = jsdom.jsdom("<html><body><p>plop</p></body></html>")
> jsdom.serializeDocument(doc)
'<html><head></head><body><p>plop</p></body></html>
> doc.querySelector("p").style
> jsdom.serializeDocument(doc)
'<html><head></head><body><p style="">plop</p></body></html>

Funnily enough, trying removing the attribute doesn't work:

> doc.querySelector("p").removeAttribute("style")
> jsdom.serializeDocument(doc)
'<html><head></head><body><p style="">plop</p></body></html>'
@domenic
Copy link
Member

domenic commented Apr 28, 2015

Nice find :-/.

@domenic domenic added the bug label Apr 28, 2015
@domenic
Copy link
Member

domenic commented Apr 28, 2015

Wow there is some funky code going on in level2/style.js... jeez.

domenic added a commit that referenced this issue May 2, 2015
This re-does everything related to attributes in jsdom, except for the Attr class itself. It is now much more spec-compliant, as it follows the spec algorithms almost exactly.

The new living/attributes.js file contains line-by-line translations of the spec algorithms, including the abstract operations referenced from elsewhere in the spec. The new living/element.js adds the appropriate Element.prototype methods, which mostly delegate to these operations.

This allows us to remove a lot of crufty and often non-compliant code spread throughout jsdom. Notable highlights include:
- Our NamedNodeMap and AttributeList implementations in level1/core (and some in level2/core); see #922
- Our dual buildup of attribute-related methods in level1/core and level2/core
- The DOMAttrModified mutation event code in level2/events, including its AttributeList monkeypatches; it was simplified and moved to Element.prototype._attrModified in level1/core
- The StyleAttr class and many monkeypatches in level2/style; instead some tweaks were made to HTMLElement in level2/html

Fixes #922. Fixes #1109.

TODO before merging:

- Split into three commits: "Minor stylesheet updates" (from another branch), the changes to validate.js and its consumers, and then the big one.
- Fix WebIDL compliance TODO in element.js
- Prefix Attr-related TODOs with "TODO Attr:" or something
domenic added a commit that referenced this issue May 3, 2015
This re-does everything related to attributes in jsdom, except for the Attr class itself. It is now much more spec-compliant, as it follows the spec algorithms almost exactly.

The new living/attributes.js file contains line-by-line translations of the spec algorithms, including the abstract operations referenced from elsewhere in the spec. The new living/element.js adds the appropriate Element.prototype methods, which mostly delegate to these operations.

This allows us to remove a lot of crufty and often non-compliant code spread throughout jsdom. Notable highlights include:
- Our NamedNodeMap and AttributeList implementations in level1/core (and some in level2/core); see #922
- Our dual buildup of attribute-related methods in level1/core and level2/core
- The DOMAttrModified mutation event code in level2/events, including its AttributeList monkeypatches; it was simplified and moved to Element.prototype._attrModified in level1/core
- The StyleAttr class and many monkeypatches in level2/style; instead some tweaks were made to HTMLElement in level2/html

Fixes #922. Fixes #1109.

Almost passes web-platform-tests at https://github.com/w3c/web-platform-tests/blob/master/dom/nodes/attributes.html, but that includes tests for Attr being a non-Node, and also has the issue referenced at whatwg/dom#31.
domenic added a commit that referenced this issue May 3, 2015
This re-does everything related to attributes in jsdom, except for the Attr class itself. It is now much more spec-compliant, as it follows the spec algorithms almost exactly.

The new living/attributes.js file contains line-by-line translations of the spec algorithms, including the abstract operations referenced from elsewhere in the spec. The new living/element.js adds the appropriate Element.prototype methods, which mostly delegate to these operations.

This allows us to remove a lot of crufty and often non-compliant code spread throughout jsdom. Notable highlights include:
- Our NamedNodeMap and AttributeList implementations in level1/core (and some in level2/core); see #922
- Our dual buildup of attribute-related methods in level1/core and level2/core
- The DOMAttrModified mutation event code in level2/events, including its AttributeList monkeypatches; it was simplified and moved to Element.prototype._attrModified in level1/core
- The StyleAttr class and many monkeypatches in level2/style; instead some tweaks were made to HTMLElement in level2/html

Fixes #922. Fixes #1109.

Almost passes web-platform-tests at https://github.com/w3c/web-platform-tests/blob/master/dom/nodes/attributes.html, but that includes tests for Attr being a non-Node, and also has the issue referenced at whatwg/dom#31.
akhaku pushed a commit to akhaku/jsdom that referenced this issue May 12, 2015
This re-does everything related to attributes in jsdom, except for the Attr class itself. It is now much more spec-compliant, as it follows the spec algorithms almost exactly.

The new living/attributes.js file contains line-by-line translations of the spec algorithms, including the abstract operations referenced from elsewhere in the spec. The new living/element.js adds the appropriate Element.prototype methods, which mostly delegate to these operations.

This allows us to remove a lot of crufty and often non-compliant code spread throughout jsdom. Notable highlights include:
- Our NamedNodeMap and AttributeList implementations in level1/core (and some in level2/core); see jsdom#922
- Our dual buildup of attribute-related methods in level1/core and level2/core
- The DOMAttrModified mutation event code in level2/events, including its AttributeList monkeypatches; it was simplified and moved to Element.prototype._attrModified in level1/core
- The StyleAttr class and many monkeypatches in level2/style; instead some tweaks were made to HTMLElement in level2/html

Fixes jsdom#922. Fixes jsdom#1109.

Almost passes web-platform-tests at https://github.com/w3c/web-platform-tests/blob/master/dom/nodes/attributes.html, but that includes tests for Attr being a non-Node, and also has the issue referenced at whatwg/dom#31.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants