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
6 changes: 5 additions & 1 deletion src/pat/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ const inject = {
return false;
}
cfg.$target = this.createTarget(cfg.target);
if (!cfg.$target) {
// Target could not be created. Abort.
return false;
}
cfg.$created_target = cfg.$target;
}
return true;
Expand Down Expand Up @@ -456,7 +460,7 @@ const inject = {
* appended to the body.
*/
if (selector.slice(0, 1) !== "#") {
log.error("only id supported for non-existing target");
log.error("only id supported for non-existing target. selector: ", selector);
return null;
}
const $target = $("<div />").attr({ id: selector.slice(1) });
Expand Down
23 changes: 23 additions & 0 deletions src/pat/inject/inject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,29 @@ describe("pat-inject", function () {
const modal = document.querySelector("#pat-modal");
expect(modal).toBeFalsy();
});

it("9.3.3 - Abort if a non-existing target cannot be created", async function () {
// Only id selectors can be created. For other selectors the
// injection is aborted before any request is made.
document.body.innerHTML = `
<a class="pat-inject"
href="test.html#document-content"
data-pat-inject="target: .not-existing">link</a>
`;

const inject = document.querySelector(".pat-inject");

pattern.init($(inject));
await utils.timeout(1); // wait a tick for async to settle.

inject.click();

await utils.timeout(1); // wait a tick for async to settle.

expect(spy_ajax).not.toHaveBeenCalled();
expect(inject.classList.contains("executing")).toBe(false);
expect(document.querySelector(".not-existing")).toBe(null);
});
});

describe("9.4 - injecton of the title element.", function () {
Expand Down