Skip to content

fix(modal): title extraction method (jquery removed .context) - #1606

Merged
petschki merged 1 commit into
5.6.xfrom
modal-fix-image-title-extraction
Jun 16, 2026
Merged

fix(modal): title extraction method (jquery removed .context)#1606
petschki merged 1 commit into
5.6.xfrom
modal-fix-image-title-extraction

Conversation

@Gomez

@Gomez Gomez commented Jun 15, 2026

Copy link
Copy Markdown
Member

Fixes JSError: Uncaught TypeError: can't access property "innerText", e.$el.context is undefined if data-pat-plone-modal="image: true"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a runtime error in the modal pattern’s image-modal path by removing reliance on the deprecated/removed jQuery .context property when extracting the modal title.

Changes:

  • Replace self.$el.context.innerText title extraction with self.$el.text() to avoid context is undefined errors for image: true.
Comments suppressed due to low confidence (1)

src/pat/modal/modal.js:660

  • title, src, and srcset are concatenated into an HTML string. If any of these values contain characters like < or quotes (e.g., via encoded text or programmatically-set attributes), this can result in HTML injection. Prefer constructing the DOM with jQuery and setting text/attributes via .text() / .attr() to ensure proper escaping.
        var title = $.trim(self.$el.text()) || "Image";
        // XXX aria?
        self.$raw = $(
            "<div><h1>" +
            title +
            '</h1><div id="content"><div class="modal-image"><img src="' +

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pat/modal/modal.js
var src = self.$el.attr("href");
var srcset = self.$el.attr("data-modal-srcset") || "";
var title = $.trim(self.$el.context.innerText) || "Image";
var title = $.trim(self.$el.text()) || "Image";
@Gomez
Gomez requested a review from petschki June 16, 2026 09:40

@petschki petschki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@petschki
petschki merged commit b348e99 into 5.6.x Jun 16, 2026
2 checks passed
@petschki
petschki deleted the modal-fix-image-title-extraction branch June 16, 2026 12:32
@petschki

Copy link
Copy Markdown
Member

@Gomez would be great if you could cherry pick this commit and create a second PR based on master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants