Skip to content

Commit

Permalink
Do not track location information for fragment-parsed nodes
Browse files Browse the repository at this point in the history
Fixes #2968.
  • Loading branch information
bakkot committed Dec 2, 2021
1 parent a61fdb8 commit f9de3fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/jsdom/browser/parser/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ function parseFragment(markup, contextElement) {

const config = {
...ownerDocument._parseOptions,
sourceCodeLocationInfo: false,
treeAdapter: new JSDOMParse5Adapter(ownerDocument, { fragment: true })
};

Expand Down
33 changes: 33 additions & 0 deletions test/api/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,39 @@ describe("API: JSDOM class's methods", () => {
endOffset: 36
});
});

it("should return undefined for nodes created by innerHTML", () => {
const dom = new JSDOM(`<p>Hello</p>`, { includeNodeLocations: true });
const para = dom.window.document.querySelector("p");

para.innerHTML = `<div></div>`;

const div = dom.window.document.querySelector("div");

assert.deepEqual(dom.nodeLocation(div), undefined);
});

it("should return undefined for nodes created by outerHTML", () => {
const dom = new JSDOM(`<p>Hello</p>`, { includeNodeLocations: true });
const para = dom.window.document.querySelector("p");

para.outerHTML = `<div></div>`;

const div = dom.window.document.querySelector("div");

assert.deepEqual(dom.nodeLocation(div), undefined);
});

it("should return undefined for nodes created by createContextualFragment", () => {
const dom = new JSDOM("", { includeNodeLocations: true });
const range = dom.window.document.createRange();

const fragment = range.createContextualFragment(`<p>Hello</p>`);

const node = fragment.querySelector("p");

assert.deepEqual(dom.nodeLocation(node), undefined);
});
});

describe("getInternalVMContext", { skipIfBrowser: true }, () => {
Expand Down

0 comments on commit f9de3fd

Please sign in to comment.