Add a lang accessor to JSDOMParser's Element - #1028
Open
afonsojanu wants to merge 1 commit into
Open
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
Element already reflects several HTML attributes as properties
(className, id, href, src, srcset) but not lang, so code that reads
doc.documentElement.lang gets undefined from a JSDOMParser document
even though the same document read through a real DOM would return
the language tag.
Readability itself isn't affected, since it reads the value with
getAttribute("lang") directly, but consumers that hand a parsed
document back to other code and expect normal DOM property access
run into this. Firefox for Android's Reader View hit exactly this
caching a parsed document and reloading it through JSDOMParser.
Fixes mozillaGH-1026.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1026.
JSDOMParser'sElementreflects several HTML attributes as properties such asclassName,id,href, andsrcset, but notlang. Code that readsdoc.documentElement.langgetsundefinedon a JSDOMParser document, even though the same document read through a real DOM would return the language tag.Readability itself isn't affected by this, since it reads the value with
getAttribute("lang")directly and exposes it aslangon the parse result. The problem hits consumers that take a document back fromJSDOMParserand read the DOM property instead, which is exactly what happened with Firefox for Android's Reader View: it caches a parsed document, reloads it throughJSDOMParser, and readsdoc.documentElement.lang, which came back empty on the cached path.Added the accessor next to the others, following the same
getAttribute/setAttributepattern the existing ones use, plus a test covering both the getter and setter. Ran the full test suite (1985 tests) and lint, both clean.