Skip to content

Open entries with active HTML in the textarea instead of the rich editor - #319

Open
mraible wants to merge 15 commits into
masterfrom
rich-editor-sanitizing
Open

mraible wants to merge 15 commits into
masterfrom
rich-editor-sanitizing

Conversation

@mraible

@mraible mraible commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Before Summernote starts, EntryEditor.jsp checks the entry with the new roller-ui/scripts/rich-editor-content.js. If the entry has HTML the rich editor would run or can't keep, it opens in the plain textarea with a notice instead of in Summernote. The entry's stored HTML is never changed, so embeds such as videos and widgets are kept, and the plain-text editor is unchanged.

The check builds what jQuery's html() builds when Summernote loads the entry, in an inert standards-mode document (document.implementation.createHTMLDocument), so resources don't load and nothing runs:

  • In place, in a div inside a form, as the rich editor sits inside the entry form, where the parser ignores the start tag of another form. It also parses the HTML outside a form, so forms the rich editor would drop show up.
  • When the HTML's first tag is a table part (which jQuery finds even inside a comment), or the HTML has <script, <style or <link, in a detached element inside the table elements jQuery adds, both the way jQuery 3 does it (wrapping the HTML in tags) and the way jQuery 4 does it (parsing inside wrapper elements).

In that tree it looks for:

  • scripts, frames, plugins (object, embed, applet), base, link, style, noscript, textarea, HTML title, xmp, noembed, noframes, plaintext, SVG set/animate, forms and form controls, and meta unless it is microdata (itemprop without name, http-equiv or charset). An SVG <title> tooltip is fine.
  • on* and formaction attributes, and javascript: or vbscript: URLs at the start of URL attributes (href, src, action, formaction, xlink:href, data, poster, background, cite and each srcset candidate). Text such as title="JavaScript: The Good Parts" doesn't count.
  • Bootstrap data API attributes (data-toggle, data-target, data-dismiss, data-slide, data-slide-to, data-bs-*), which act on clicks anywhere in the page.
  • Text Summernote would later parse as HTML: an href with a < in it, and a URL-like word with a < in it, which autolink turns into a link when the author types a space after it. Code samples such as a &lt; b stay in the rich editor.

It then serializes the tree and loads it again, as undo does, and compares the elements, their namespaces and attributes (not the text, so a <pre> starting with a blank line is fine). It also follows the HTML through Summernote 0.9's code view filter, which removes some tags when the author leaves code view, and opens HTML with an <iframe anywhere in it, even in a comment, in the textarea.

Media inserted while the textarea is showing goes into the textarea, since Summernote starts itself on any call: at the cursor when one has been placed, including at the very start, and at the end otherwise. The leave-page warning is armed on the first edit, by typing in the textarea or a Summernote change, and armed again after a submit that keeps the page open.

This only applies to weblogs that use Summernote. Its editor id is editor-xinha.jsp, so weblogs with an old xinha editor value get Summernote and this check. plugins.defaultEditor=editor-summernote.jsp matches no editor, so other values that name an editor that no longer exists (such as ekit) fall back to the first configured editor, the plain textarea. This PR doesn't change that lookup.

Tests:

  • EntryEditorRichContentTest checks that the page loads the script, that every .summernote( call is either the init after the check or the guarded pasteHTML, that the leave warning is armed again after a submit, and that the textarea fallback inserts media at the cursor.
  • The new RichEditorContentIT in it-playwright loads the script into a blank page in Chromium, with no running Roller, and checks entries that must open in the textarea, entries that should stay in the rich editor, and where media files are inserted. It also loads entries with the jQuery 4.0.0 webjar (a new test dependency) and checks that whatever the check lets through has no event handlers once jQuery has loaded it.
  • The new user journey test switches a weblog to the rich editor, opens an entry with a click handler in the textarea, and checks the leave warning after typing and after inserting a media file.

The CHANGES entry for this PR, added in #324, now also lists the other entries that open in the textarea: forms, some Bootstrap data attributes, a link or URL-like word containing <, and an iframe or a tag that code view removes, even in a comment.

Before Summernote starts, EntryEditor.jsp checks the entry's HTML with the new rich-editor-content.js, which parses it in an inert DOMParser document and looks for scripts, frames, plugins, document-level elements, noscript, SVG set and animate, on* attributes, and javascript: or vbscript: URLs in any attribute. When it finds any, the entry opens in the plain HTML textarea with a short notice, and media files are inserted into the textarea, since Summernote would start itself on any call. Other entries open in Summernote as before. The stored HTML isn't changed, and the plain text editor is unchanged.
… elements

jQuery's html(), which Summernote uses to load an entry, keeps table cells, rows and captions found outside a table, while a full document parse drops them and their attributes. rich-editor-content.js now also checks the entry parsed as template contents, which keeps them, and treats <style> elements as active since they apply to the whole page. Media files inserted into the textarea fallback go at the cursor, or at the end when it has none.

@snoopdave snoopdave 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.

Review of e3631e50c: The changed lines match #331 across all four files. I found two editor behavior regressions and a gap in the automated test; no build was run under the review constraints.

… of the textarea, and test the rich editor check in a browser

rich-editor-content.js now looks for javascript: and vbscript: URLs only at the start of URL attributes (href, src, action, formaction, xlink:href, data, poster, background, cite and each srcset candidate), so text such as title="JavaScript: The Good Parts" no longer opens an entry in the textarea. Entries with textarea, title, xmp, noembed, noframes or plaintext elements, or with markup that parses differently once serialized and parsed again (as the rich editor does for undo and code view), open in the textarea too.

The textarea fallback now remembers whether the cursor has been placed, so a media file goes at the start when the cursor was put there, and at the end only when it never was.

The new RichEditorContentIT in it-playwright loads the script into a blank page and checks entries that should open in the textarea, entries that should stay in the rich editor, and where media files are inserted. It needs no running Roller.
…arses the same way twice

The serialize-and-parse-again check in rich-editor-content.js compared serialized HTML, so a <pre> starting with a blank line, which loses one leading newline each time it is parsed, opened in the textarea. It now compares the elements, their namespaces and attributes, and leaves text out. RichEditorContentIT checks that case.
@mraible

mraible commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

A second review raised a few more points, now addressed in the latest commits:

  • Also from review: entries with textarea, title, xmp, noembed, noframes or plaintext elements now open in the textarea, and so do entries whose element tree changes when it is serialized and parsed again, as the rich editor does for undo and code view (nested forms and the math/mglyph cases). The comparison covers elements, namespaces and attributes but not text, so a pre starting with a blank line stays in the rich editor; RichEditorContentIT covers these cases.
  • On the editor setting: Summernote's editor id is editor-xinha.jsp, so weblogs with the old xinha value get Summernote directly, but plugins.defaultEditor=editor-summernote.jsp matches no configured editor, so weblogs with other unknown values (such as ekit) fall back to the first configured editor, the plain text one. This PR doesn't change that lookup; the description will be corrected to say so.

@mraible
mraible requested a review from snoopdave November 18, 2026 04:16
…form controls in the textarea

The rich editor loads an entry inside the entry form, where the parser ignores the start tag of another form, so the content check now also parses and re-parses the HTML inside a form and no longer misses markup that only becomes an element with an event handler there.

Entries with a form, input, button or select element, or a formaction attribute, now open in the HTML textarea. The rich editor dropped a form's own tags on save, and such controls became part of the entry form, where they could be submitted with the entry or send it to another address.

The check reads attributes and child nodes through the DOM prototypes, so a form control named attributes or firstChild can no longer hide its form's attributes from it.

The leave-page warning is now attached on the first rich editor change only, instead of once more on every change, and the test that guards Summernote command calls matches single-quoted command names too.

The check also reads the parsed document's body and calls its createElement and querySelectorAll through the DOM prototypes. In Firefox an image named body, createElement or querySelectorAll replaces that property on the parsed document, which made a harmless image with such a name open in the textarea and left the body comparison looking at the image instead of the body.

@snoopdave snoopdave 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.

Review of d14eaded9: The earlier editor and cursor issues are resolved, and the production changes match #331. The new textarea path can miss the unsaved-edit warning while the field remains focused. #319 also has one MathML parser test case absent from #331; the other test differences follow the branches’ test frameworks.

Earlier comments: 5 of 5 resolved.

The textarea fallback installed the leave-page warning on change, which fires only after the field loses focus, so an author who typed and closed the tab while still in the field got no warning. It now listens for the first input event, and media insertion triggers input. The new user journey switches its weblog to the rich editor, opens an entry with a click handler in the textarea, and checks the warning is armed after typing and after inserting a media file.
mraible added a commit to mraible/roller that referenced this pull request Nov 20, 2026
Adds bug-fix and behaviour-change entries for apache#313 to apache#319 and apache#321 to apache#323.
…aves them

The content check parsed entries with DOMParser, a template and a div in a form, which only approximate how the rich editor loads them. DOMParser also parses without a doctype, in quirks mode, while the editor page is in standards mode, so the same HTML could become a different tree there.

The check now builds what jQuery's html() builds, in an inert standards-mode document: in place in the rich editor inside the entry form, or, for HTML whose first tag is a table part or that has script, style or link tags, in a detached element inside the table elements jQuery adds, the way both jQuery 3 and 4 do it. It checks that tree and checks that loading its serialized HTML again, as undo does, gives the same elements.

Leaving Summernote 0.9's code view removes some tags from the HTML, which can end a comment early, so the check also follows the serialized HTML through that filter, and HTML with an iframe tag anywhere in it, even in a comment, opens in the textarea.

RichEditorContentIT now loads entries with the jQuery webjar for its check that what stays in the rich editor has no event handlers.
… attributes, in the textarea

Summernote shows some text from the entry as HTML: its autolink parses a URL-like word as HTML when the author types a space after it, and Summernote 0.8's link popover does the same with a link's href. Entries with a URL-like word that has a < in it, or an href with a < in it, now open in the HTML textarea. Other text with < in it, such as code samples, stays in the rich editor.

Bootstrap's data API acts on clicks anywhere in the page, and Bootstrap 3 loads a link into the dialog it names, so entries with data-toggle, data-target, data-dismiss, data-slide, data-slide-to or data-bs-* attributes open in the textarea too.
The check treated every element named title or meta as active, so an inline SVG with a <title> tooltip, or schema.org microdata written as <meta itemprop content>, opened in the HTML textarea. It now flags only an HTML <title>, and a <meta> unless it has itemprop and none of name, http-equiv and charset.
The notice used a doubled apostrophe, which shows as two unless the message goes through MessageFormat, and the page shows it without parameters. It now says cannot, which reads the same either way.
The leave-page warning was armed on the first edit only, and a submit removed it for good, so after a submit that was stopped before the page changed, later edits could be lost without a prompt. The submit handler now arms the warning again for the next edit, in the rich editor and in the HTML textarea.
…a command name

The test that Summernote only starts after the content check matched calls that pass a quoted command name, so a call that passes a variable, no arguments or a second options object would not have been seen. It now matches every .summernote( call and expects exactly the init after the check and the guarded pasteHTML.
…path

When the HTML has a script, style or link tag but doesn't start with a table part, jQuery 3 parses it without any wrapper, but the check added an empty <> around it, which left stray text in its parse. RichEditorContentIT covers an entry with a link tag in a comment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants