Skip to content

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

Open
mraible wants to merge 15 commits into
roller-6.1.xfrom
rich-editor-sanitizing-6.1.x
Open

mraible wants to merge 15 commits into
roller-6.1.xfrom
rich-editor-sanitizing-6.1.x

Conversation

@mraible

@mraible mraible commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The 6.1.x version of #319. rich-editor-content.js is the same file on both branches, so the check is described there; in short, entries with HTML the rich editor would run or can't keep open in the plain textarea with a notice, and the stored HTML is never changed.

What differs on 6.1.x:

  • The page uses jQuery 3.7.1, Bootstrap 3.4.1 and Summernote 0.8.12. The check builds what jQuery's html() builds for both jQuery 3 and 4, so it covers this branch's jQuery 3 table-part wrapping.
  • Summernote 0.8.12's link popover parses a link's href as HTML, and its autolink does the same with a URL-like word when the author types a space after it, so an href or a URL-like word with a < in it opens the entry in the textarea. Code samples such as a &lt; b stay in the rich editor.
  • Bootstrap 3's data API acts on clicks anywhere in the page and can load 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.
  • Summernote 0.8.12 doesn't filter HTML when the author leaves code view, but the check still follows the HTML through 0.9's filter, since the file is shared. Only entries with tags in comments or attributes are affected.
  • The notice uses Bootstrap 3's alert alert-info. Summernote 0.8.12 also starts itself on any call, so the media insertion guard applies as on master.

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.

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-selenium checks the detection and media insertion in Firefox, with no running Roller. It also loads entries with the jQuery 3.7.1 webjar (a new test dependency) and checks that whatever the check lets through has no event handlers once jQuery has loaded it.

The 6.1.8 CHANGES entry for this PR, added in #336, 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.
@mraible mraible changed the title Check table parts the way the rich editor parses them, and flag style elements Open entries with active HTML in the textarea instead of the rich editor Nov 18, 2026

@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 40f7b300e: The fix hunks match #319; I found no missing backport change. The textarea fallback has one cursor placement regression, and the committed test does not check the detector’s behavior.

… 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-selenium loads the script into a blank page in Firefox 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; to run it without the module's Jetty, use mvn test-compile failsafe:integration-test failsafe:verify -Dit.test=RichEditorContentIT from it-selenium.
…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:

@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 1a4d826ba: The production fix matches #319, and both earlier review points are resolved. The textarea fallback has a leave-page warning gap, and its browser test omits one case covered by the twin.

Earlier comments: 2 of 2 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. InitialLoginTestIT 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. RichEditorContentIT also gets the MathML and table case that the master test has.
…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.

Summernote 0.9's code view removes some tags from the HTML when the author leaves it, which can end a comment early. Summernote 0.8.12 doesn't by default, but the check is the same file on both branches and 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 0.8.12 shows some text from the entry as HTML: its link popover parses a link's href as HTML when the caret is in the link, and its autolink does the same with a URL-like word when the author types a space after it. Entries with an href that has a < in it, or a URL-like word that has a < in it, now open in the HTML textarea. Other text with < in it, such as code samples, stays in the rich editor.

Bootstrap 3's data API acts on clicks anywhere in the page, and 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