+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/dom-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ function normalizeLineEndings(input) {
* @see https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-parsing-and-serialization
*/
function DOMParser(options) {
options = options || { locator: true };
options = options || {};
if (options.locator === undefined) {
options.locator = true;
}

/**
* The method to use instead of `conventions.assign`, which is used to copy values from
Expand Down
16 changes: 15 additions & 1 deletion test/dom-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,26 @@ describe('DOMParser', () => {
};
expect(doc.documentElement).toMatchObject(expected);
});
test("should not use locator when it's not set in options", () => {
test("should use locator when it's not explicitly set to false in options", () => {
const options = {};
const it = new DOMParser(options);

const doc = it.parseFromString('<xml/>', MIME_TYPE.XML_TEXT);

const expected = {
columnNumber: 1,
lineNumber: 1,
};
expect(doc.documentElement).toMatchObject(expected);
});
test("should not use locator when it's set to false in options", () => {
const options = {
locator: false,
};
const it = new DOMParser(options);

const doc = it.parseFromString('<xml/>', MIME_TYPE.XML_TEXT);

expect(doc.documentElement).not.toHaveProperty('columnNumber');
expect(doc.documentElement).not.toHaveProperty('lineNumber');
});
Expand Down
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载